From de31559200c11c257a7be9ad49a12a8efe9c68cc Mon Sep 17 00:00:00 2001 From: Mauro Andre Date: Mon, 7 Oct 2024 17:12:58 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20create=20index=20after=20i?= =?UTF-8?q?n=20model=20after=20a=20nested=20attr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyodmongo/services/model_init.py | 3 ++- tests/test_db_index.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pyodmongo/services/model_init.py b/pyodmongo/services/model_init.py index 1b4396f..249bce8 100644 --- a/pyodmongo/services/model_init.py +++ b/pyodmongo/services/model_init.py @@ -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 diff --git a/tests/test_db_index.py b/tests/test_db_index.py index 97077da..8168280 100644 --- a/tests/test_db_index.py +++ b/tests/test_db_index.py @@ -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() @@ -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