Skip to content

Commit

Permalink
Merge pull request #148 from mauro-andre/fix_create_index_in_attr_aft…
Browse files Browse the repository at this point in the history
…er_fested_creation

🐛 Fix create index after in model after a nested attr
  • Loading branch information
mauro-andre authored Oct 7, 2024
2 parents 9acc178 + de31559 commit 39b26f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyodmongo/services/model_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __ordinary_index_and_text_keys(
indexes_path=indexes_path,
text_indexes_path=text_indexes_path,
)
pass
indexes_path.pop()
text_indexes_path.pop()
if not cls.model_fields[key].json_schema_extra:
continue
is_index = cls.model_fields[key].json_schema_extra.get("index") or False
Expand Down
2 changes: 2 additions & 0 deletions tests/test_db_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class RecModelTest(DbModel):
attr_1: str = "attr_1"
attr_2: str = Field(default="attr_2", index=True)
attr_persisted: Persisted = Persisted()
attr_3: str = Field(default="attr_3", index=True)
_collection: ClassVar = "rec_model_test"

await async_engine._db[RecModelTest._collection].drop()
Expand All @@ -250,6 +251,7 @@ async def test_index_creation_with_persisted_nested(
].index_information()
assert "attr_1" not in indexes_in_db
assert "attr_2" in indexes_in_db
assert "attr_3" in indexes_in_db
assert "attr_persisted" not in indexes_in_db
assert "attr_persisted.attr_p1" not in indexes_in_db
assert "attr_persisted.attr_p2" in indexes_in_db
Expand Down

0 comments on commit 39b26f6

Please sign in to comment.