Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JosXa opened this issue Sep 27, 2020 · 1 comment
Open

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

JosXa opened this issue Sep 27, 2020 · 1 comment

Comments

@JosXa
Copy link

JosXa commented Sep 27, 2020

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:

@staticmethod
def equal(index: IndexModel, db_index: SON) -> bool:
"""Compares the specified ``index`` and ``db_index``.
This method return ``True`` if the ``index`` specification can be considered
equal to the existing ``db_index`` in the database.
"""
dbi = db_index.copy()
del dbi["v"]
del dbi["ns"]
return dbi == index.document # type: ignore

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 <module>
    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
Copy link

sabbyX commented Oct 10, 2020

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

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

No branches or pull requests

2 participants