Skip to content

Conversation

@abrookins
Copy link
Collaborator

Summary

Fixes #496 - EmbeddedJsonModel was generating primary keys with ULIDs even though embedded models don't need them (they're stored as part of their parent document, not as separate Redis keys).

Changes

  1. EmbeddedJsonModel.pk field: Override to use Field(default=None, exclude=True) so pk is excluded from serialization
  2. validate_pk validator: Skip pk generation for embedded models (return None)
  3. validate_primary_key: Skip primary key validation for embedded models
  4. Metaclass: Clear _meta.primary_key for embedded models
  5. Test update: Updated test_schema to reflect that embedded model pk fields are no longer in the RediSearch schema

Before

from aredis_om import EmbeddedJsonModel

class Address(EmbeddedJsonModel):
    city: str

addr = Address(city="Portland")
print(addr.pk)  # 01KFXVST2B7R8ZWBDZN21KX24P (unwanted ULID)
print(addr.model_dump())  # {'pk': '01KFXVST2B7R8ZWBDZN21KX24P', 'city': 'Portland'}

After

from aredis_om import EmbeddedJsonModel

class Address(EmbeddedJsonModel):
    city: str

addr = Address(city="Portland")
print(addr.pk)  # None
print(addr.model_dump())  # {'city': 'Portland'}

EmbeddedJsonModels are stored as part of their parent document, not as
separate Redis keys, so they don't need primary keys.

Fixes #496
@abrookins abrookins merged commit 23548bf into main Jan 26, 2026
15 checks passed
@abrookins abrookins deleted the fix/embedded-json-model-no-pk branch January 26, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disable generation of primary keys on EmbeddedJsonModels

2 participants