You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After appending an object to a list of CachedReferenceFields, I get this error when trying to fetch the object:
AttributeError: 'CachedReferenceField' object has no attribute '_get_db'
File "build/bdist.macosx-10.10-x86_64/egg/mongoengine/dereference.py", line 145, in _fetch_objects
references = doc_type._get_db()[collection].find({'_id': {'$in': refs}})
AttributeError: 'CachedReferenceField' object has no attribute '_get_db'
Any clue?
The text was updated successfully, but these errors were encountered:
We're having the same issue except with EmbeddedDocumentField instead of CachedReferenceField.
To elaborate, in line 130 of mongoengine/dereference.py - where it checks hasattr(collection,'objects') - it returns false where it should be true.
We ran a debugger and checked hasattr(collection,'objects'). This returned False first, and True immediately after even though it's exactly (or should be) the same object being checked.
We were able to temporarily fix this issue but adding line 130 as pictured below to the above referenced dereference.py:
I believe the root cause of your problem is hidden by hasattr. In fact under python2 hasattr swallows any errors that occurs within the call and returns False (as if the attribute simply does not exist, hiding the exception that occured). hasattr(collection, 'objects') is actually going through some code (including potentially creating indexes if they don't exist yet).
The behavior you describe is similar to #1688 and #1522.
That part of the code got improved (#1858) by replacing the hasattr by getattr which should allow you to get the actual exception. Retry your code using the latest master, you should get the actual exception now.
After appending an object to a list of CachedReferenceFields, I get this error when trying to fetch the object:
AttributeError: 'CachedReferenceField' object has no attribute '_get_db'
File "build/bdist.macosx-10.10-x86_64/egg/mongoengine/dereference.py", line 145, in _fetch_objects
references = doc_type._get_db()[collection].find({'_id': {'$in': refs}})
AttributeError: 'CachedReferenceField' object has no attribute '_get_db'
Any clue?
The text was updated successfully, but these errors were encountered: