Skip to content

select_related() ConnectionError  #1688

@radulucaciu

Description

@radulucaciu

Hi,

I am having an interesting situation. We have been using MongoEngine in our project for a good few years now and this issue appeared out of nowhere (no update, no change to the code).

Calling select_related() on the results of a query raises a mongoengine.connection.ConnectionError: You have not defined a default connection Exception

The call that causes the issue:
credentials = Credential.objects(id__in=ids).select_related()

I noticed that I am getting the exception only the first time time I call select_related() and only on this object. Any subsequent calls (on the same collection) work as expected.

While trying to debug, I got to this:

> /usr/local/lib/python2.7/dist-packages/mongoengine/dereference.py(129)_fetch_objects()
    127         object_map = {}
    128         for collection, dbrefs in self.reference_map.iteritems():
--> 129             if hasattr(collection, 'objects'):  # We have a document class for the refs
    130                 col_name = collection._get_collection_name()
    131                 refs = [dbref for dbref in dbrefs

ipdb> collection
<class 'insights.models.company.Company'>
ipdb> hasattr(collection, 'objects')
False
ipdb> hasattr(collection, 'objects')
True

Can this be caused by some lazy loading or some configuration issue?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions