Skip to content

Commit dda2897

Browse files
slorello89Savannah Norem
and
Savannah Norem
authored
fixing schema parsing in json models with non-str pks (#622)
Co-authored-by: Savannah Norem <[email protected]>
1 parent 44cbeaf commit dda2897

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

aredis_om/model/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,9 @@ def schema_for_fields(cls):
19841984
if issubclass(_type, str):
19851985
redisearch_field = f"$.{name} AS {name} TAG SEPARATOR {SINGLE_VALUE_TAG_FIELD_SEPARATOR}"
19861986
else:
1987-
redisearch_field = cls.schema_for_type(name, _type, field_info)
1987+
redisearch_field = cls.schema_for_type(
1988+
json_path, name, "", _type, field_info
1989+
)
19881990
schema_parts.append(redisearch_field)
19891991
continue
19901992
schema_parts.append(

tests/test_hash_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ class ModelWithStringDefault(HashModel):
900900
assert res.test == "None"
901901

902902

903+
@py_test_mark_asyncio
903904
async def test_update_validation():
904905
class TestUpdate(HashModel):
905906
name: str

tests/test_json_model.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# type: ignore
22

33
import abc
4+
import asyncio
45
import dataclasses
56
import datetime
67
import decimal
@@ -994,8 +995,8 @@ class ModelWithStringDefault(JsonModel):
994995
assert res.test == "None"
995996

996997

998+
@py_test_mark_asyncio
997999
async def test_update_validation():
998-
9991000
class Embedded(EmbeddedJsonModel):
10001001
price: float
10011002
name: str = Field(index=True)
@@ -1025,6 +1026,7 @@ class TestUpdatesClass(JsonModel):
10251026
assert rematerialized.age == 42
10261027

10271028

1029+
@py_test_mark_asyncio
10281030
async def test_model_with_dict():
10291031
class EmbeddedJsonModelWithDict(EmbeddedJsonModel):
10301032
dict: Dict
@@ -1071,6 +1073,17 @@ class Example(JsonModel):
10711073
assert res.name == ex.name
10721074

10731075

1076+
@py_test_mark_asyncio
1077+
async def test_int_pk():
1078+
class ModelWithIntPk(JsonModel):
1079+
my_id: int = Field(index=True, primary_key=True)
1080+
1081+
await Migrator().run()
1082+
await ModelWithIntPk(my_id=42).save()
1083+
1084+
m = await ModelWithIntPk.find(ModelWithIntPk.my_id == 42).first()
1085+
assert m.my_id == 42
1086+
10741087
@py_test_mark_asyncio
10751088
async def test_pagination():
10761089
class Test(JsonModel):

0 commit comments

Comments
 (0)