canonical / testflinger

https://testflinger.readthedocs.io/en/latest/
GNU General Public License v3.0
11 stars 17 forks source link

AttributeError: Collection has no attribute '_Collection__database'. To access the fs._Collection__database collection, use database['fs._Collection__database']. #367

Open plars opened 3 days ago

plars commented 3 days ago

Server fails to start after pymongo 4.9.0 release It looks like pymongo 4.9.0 was released a few days ago. We don't depend on it directly, but flask-pymongo imports it. Unfortunately some things have changed with GridFS that break with this version. We see this show up in the unit tests also due to incompatibility with the current version of mongomock, but the first breakage you see is when trying to start the server:

  File "/srv/testflinger/testflinger.py", line 22, in <module>
    app = create_flask_app()
  File "/srv/testflinger/src/application.py", line 58, in create_flask_app
    setup_mongodb(tf_app)
  File "/srv/testflinger/src/database.py", line 73, in setup_mongodb
    create_indexes()
  File "/srv/testflinger/src/database.py", line 90, in create_indexes
    mongo.db.fs.chunks.create_index(
  File "/usr/local/lib/python3.10/dist-packages/flask_pymongo/wrappers.py", line 85, in __getattr__
    attr = super(Collection, self).__getattr__(name)
  File "/usr/local/lib/python3.10/dist-packages/pymongo/synchronous/collection.py", line 282, in __getattr__
    return self.__getitem__(name)
  File "/usr/local/lib/python3.10/dist-packages/flask_pymongo/wrappers.py", line 94, in __getitem__
    db = self._Collection__database
  File "/usr/local/lib/python3.10/dist-packages/flask_pymongo/wrappers.py", line 85, in __getattr__
    attr = super(Collection, self).__getattr__(name)
  File "/usr/local/lib/python3.10/dist-packages/pymongo/synchronous/collection.py", line 278, in __getattr__
    raise AttributeError(
AttributeError: Collection has no attribute '_Collection__database'. To access the fs._Collection__database collection, use database['fs._Collection__database'].
[2024-09-18 23:15:29 +0000] [7] [INFO] Worker exiting (pid:

I've looked into this a bit, and it seems to be due to a change made to add Beta support for async in pymongo. I've not yet worked out if this is something that needs updates in flask-pymongo and mongomock or something that's just broken for now in pymongo, but until we sort it out, we should not allow it to update to the latest pymongo that includes this change.

I've proposed https://github.com/canonical/testflinger/pull/366 as a workaround for now

syncronize-issues-to-jira[bot] commented 3 days ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CERTTF-421.

This message was autogenerated