Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing schema parsing in json models with non-str pks #622

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,9 @@ def schema_for_fields(cls):
if issubclass(_type, str):
redisearch_field = f"$.{name} AS {name} TAG SEPARATOR {SINGLE_VALUE_TAG_FIELD_SEPARATOR}"
else:
redisearch_field = cls.schema_for_type(name, _type, field_info)
redisearch_field = cls.schema_for_type(
json_path, name, "", _type, field_info
)
schema_parts.append(redisearch_field)
continue
schema_parts.append(
Expand Down
1 change: 1 addition & 0 deletions tests/test_hash_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ class ModelWithStringDefault(HashModel):
assert res.test == "None"


@py_test_mark_asyncio
async def test_update_validation():
class TestUpdate(HashModel):
name: str
Expand Down
16 changes: 15 additions & 1 deletion tests/test_json_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# type: ignore

import abc
import asyncio
import dataclasses
import datetime
import decimal
Expand Down Expand Up @@ -994,8 +995,8 @@ class ModelWithStringDefault(JsonModel):
assert res.test == "None"


@py_test_mark_asyncio
async def test_update_validation():

class Embedded(EmbeddedJsonModel):
price: float
name: str = Field(index=True)
Expand Down Expand Up @@ -1025,6 +1026,7 @@ class TestUpdatesClass(JsonModel):
assert rematerialized.age == 42


@py_test_mark_asyncio
async def test_model_with_dict():
class EmbeddedJsonModelWithDict(EmbeddedJsonModel):
dict: Dict
Expand Down Expand Up @@ -1069,3 +1071,15 @@ class Example(JsonModel):

res = await Example.find(Example.d == ex.d and Example.b == True).first()
assert res.name == ex.name


@py_test_mark_asyncio
async def test_int_pk():
class ModelWithIntPk(JsonModel):
my_id: int = Field(index=True, primary_key=True)

await Migrator().run()
await ModelWithIntPk(my_id=42).save()

m = await ModelWithIntPk.find(ModelWithIntPk.my_id == 42).first()
assert m.my_id == 42
Loading