Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ def validate_primary_key(cls):
else:
field_info = field.field_info

if getattr(field_info, "primary_key", None):
if getattr(field_info, "primary_key", None) is True:
primary_keys += 1
if primary_keys == 0:
raise RedisModelError("You must define a primary key for the model")
Expand Down Expand Up @@ -1808,7 +1808,7 @@ def schema_for_fields(cls):
else:
field_info = field.field_info

if getattr(field_info, "primary_key", None):
if getattr(field_info, "primary_key", None) is True:
if issubclass(_type, str):
redisearch_field = (
f"{name} TAG SEPARATOR {SINGLE_VALUE_TAG_FIELD_SEPARATOR}"
Expand Down Expand Up @@ -2003,7 +2003,7 @@ def schema_for_fields(cls):
field_info = field.field_info
else:
field_info = field
if getattr(field_info, "primary_key", None):
if getattr(field_info, "primary_key", None) is True:
if issubclass(_type, str):
redisearch_field = f"$.{name} AS {name} TAG SEPARATOR {SINGLE_VALUE_TAG_FIELD_SEPARATOR}"
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_json_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,16 @@ class TestLiterals(JsonModel):
assert rematerialized.pk == item.pk


@py_test_mark_asyncio
async def test_two_false_pks():
from pydantic_core import PydanticUndefined as Undefined

class SomeModel(JsonModel):
field1: str = Field(index=True, primary_key=Undefined)
field2: str = Field(index=True, primary_key=Undefined)

SomeModel(field1="foo", field2="bar")

@py_test_mark_asyncio
async def test_merged_model_error():
class Player(EmbeddedJsonModel):
Expand Down
Loading