MongoEngine / MongoEngine/mongoengine
DynamicDocument collection's name will be changed after pickle dumps and loads
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Reproduce:
class DynamicTaskResult(DynamicDocument):
pass
result = DynamicTaskResult()
result.switch_collection("test1")
print(result._collection.full_name)
obj = pickle.dumps(result)
revert = pickle.loads(obj)
print(revert._collection.full_name) # not "test1", but "dynamic_task_result"
Here's a screenshot with pycharm debug:

It shows that collection name does changed after pickle dumps and loads.
My mongoengine version is 0.16.3 and pymongo version is 3.7.2
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 by running the reported DynamicTaskResult reproduction with pickle and compare _collection.full_name before and after loading. Trace DynamicDocument's pickle serialization and collection-switching behavior; done means the switched collection remains "test1" after the pickle round trip.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100