MongoEngine / MongoEngine/mongoengine
Cannot use to_json in pre_init
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
File ".../venv/lib/python3.7/site-packages/mongoengine/base/document.py", line 423, in to_json
return json_util.dumps(self.to_mongo(use_db_field), *args, **kwargs)
File ".../venv/lib/python3.7/site-packages/mongoengine/document.py", line 252, in to_mongo
data = super(Document, self).to_mongo(*args, **kwargs)
File ".../venv/lib/python3.7/site-packages/mongoengine/base/document.py", line 328, in to_mongo
value = self._data.get(field_name, None)
AttributeError: _data
signals.pre_init.connect(pre_init)
pre_init has document as second argument. The the pre_init function is invoked, document is empty. to_json should return an empty json object.
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 reproducing the pre_init failure and read the referenced paths in mongoengine/base/document.py around lines 328 and 423, plus document.py around line 252. Trace how the empty document reaches to_json, then add coverage for the reported case; done means calling to_json in pre_init returns an empty JSON object without raising AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100