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

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

Open
plars opened this issue Sep 28, 2024 · 1 comment

Comments

@plars
Copy link
Collaborator

plars commented Sep 28, 2024

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 #366 as a workaround for now

Copy link

Thank you for reporting us your feedback!

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

This message was autogenerated

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

1 participant