codello / Motor-ODM

A MongoDB ODM based on Motor and Pydantic.
MIT License
17 stars 5 forks source link

ValueError: list.remove(x): x not in list #29

Open JosXa opened 4 years ago

JosXa commented 4 years ago

Hey there, finally starting to get my feet wet with this library.

I'm trying to use your wrapper for updating indices in the database, but the static method IndexManager.equal fails when attempting to delete ns from dbi:

https://github.com/codello/Motor-ODM/blob/15fdad8e2acf088b807dc4f69da6730590aecbd4/motor_odm/indexes.py#L91-L101

I don't think I'm doing anything special, just following the example from your tests. Sounds to me like the values just shouldn't be used for comparison and we can add an if "ns" in dbi: ... check beforehand?

Stack Trace

``` Traceback (most recent call last): File "C:/projects/josxabot/app/modules/symbose/models/item.py", line 59, in asyncio.get_event_loop().run_until_complete(main()) File "c:\program files\python38\lib\asyncio\base_events.py", line 616, in run_until_complete return future.result() File "C:/projects/josxabot/app/modules/symbose/models/item.py", line 49, in main await User.init_indexes(drop=True) File "c:\users\int002327\appdata\local\pypoetry\cache\virtualenvs\josxabot-c3bmtbt9-py3.8\src\motor-odm\motor_odm\document.py", line 272, in init_indexes await im.ensure_indexes(cls.__mongo__.indexes, drop=drop) File "c:\users\int002327\appdata\local\pypoetry\cache\virtualenvs\josxabot-c3bmtbt9-py3.8\src\motor-odm\motor_odm\indexes.py", line 49, in ensure_indexes elif self.equal(index, db_index): File "c:\users\int002327\appdata\local\pypoetry\cache\virtualenvs\josxabot-c3bmtbt9-py3.8\src\motor-odm\motor_odm\indexes.py", line 100, in equal del dbi["ns"] File "C:\Users\INT002327\AppData\Local\pypoetry\Cache\virtualenvs\josxabot-c3BmTbt9-py3.8\lib\site-packages\bson\son.py", line 63, in __delitem__ self.__keys.remove(key) ValueError: list.remove(x): x not in list ```

Kudos, I love the idea of combining Pydantic with... well... anything ;D

sabbyX commented 4 years ago

MongoDB has stopped generating ns fields in indexes. (ref)