-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Dereferencing causing TypeError at first run #1522
Comments
Hi @ripperdoc! Thank you for reporting this issue. Could you share what your document's schema is? And does calling |
Hi, I've improved something in that part of the code which should allow you to get the actual root cause. In fact under python2 hasattr is swallowing any exceptions that occurs during the hasattr call and return False in case one is thrown. So using getattr is a safer approach since we must be python2/3. See below:
Issue #1688 had a comparable problem (first call to to .select_related() was failing but second was passing), It turned out to be a problem with an index creation error that was swallowed in that case. Please retry your code with the latest master, most likely there is an exception being swallowed and you should now see it |
I'm closing this since it spent a lot of time waiting for a feedback from the author. @ripperdoc Please note that the latest release (0.16.0) includes the fix I mentioned in my last post which should allow you to see the actual error. In case you are still experiencing this with the latest version, provide us additional details and I'll be happy to re-open this ticket |
This is a peculiar error that seem to have appeared since I upgraded to 0.10.6. I use a pagination library that calls select_related() on the QuerySet. The first time this happens at each execution, this causes a TypeError from PyMongo. The error disappears at subsequent requests, but re-appears if I restart the process.
Digging into the code, the problem occurs at
mongoengine/dereference.py", line 150, in _fetch_objects
. The checkif hasattr(collection, 'objects')
will return False even if it encounters aTopLevelDocumentMetaclass
instance, that should haveobjects
. Instead it goes to the else clause, where it assumes that the variablecollection
is a string. When it callsreferences = get_db()[collection].find({'_id': {'$in': refs}})
it throws a TypeError from PyMongo as it encounters a class ofTopLevelDocumentMetaclass
notbasestring
.It feels like some race condition, where the attribute objects cannot be found on something that should have it. A safer approach could be to not assume
collection
variable can be sent to PyMongo without verifying / coercing it to a string.See code below and stacktrace:
The text was updated successfully, but these errors were encountered: