MongoEngine / MongoEngine/mongoengine
Concurrent switch_db failure
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
I have multiple green threads that try to with switch_db(SomeDocument, alias):... on the same document in order to query multiple aliases.
Once in a while I get an exception:
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/queryset.py", line 104, in count
return super(QuerySet, self).count(with_limit_and_skip)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 347, in count
return self._cursor.count(with_limit_and_skip=with_limit_and_skip)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 1481, in _cursor
self._cursor_obj = self._collection.find(self._query,
AttributeError: 'NoneType' object has no attribute 'find'
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/queryset.py", line 104, in count
return super(QuerySet, self).count(with_limit_and_skip)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 347, in count
return self._cursor.count(with_limit_and_skip=with_limit_and_skip)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 1481, in _cursor
self._cursor_obj = self._collection.find(self._query,
AttributeError: 'NoneType' object has no attribute 'find'
It happens possibly due to self.cls._collection = None in switch_db.enter function.
I'm using mongoengine 0.10.6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with switch_db.enter and the _cursor path in mongoengine/queryset/base.py, especially where self.cls._collection becomes None. Reproduce the failure with concurrent green threads querying multiple aliases, then verify that concurrent switch_db use no longer produces a NoneType.find error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100