MongoEngine / MongoEngine/mongoengine
from_json not working on the existing documents
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
I am trying to update the document and I need to skip validations while updating the document. I have data in json format and I tried the following two ways.
1.
profile = Profile.objects({"id": profile_id}).get()
profile.update(**data)
profile.reload()
return profile
But the problem with this is I can't specify the validate False flag with this method.
profile = Profile.objects({"id": profile_id}).get()
profile = profile.from_json(json.dumps(data))
profile.id = profile_id
profile = profile.save(validate=False)
profile.reload()
return profile
To my surprise, this method is not updating the document at all. This returns the same old document. Am I doing something wrong or is this a bug in from_json method.
Note: I have a very long document which has a lot of embedded documents. so parsing json manually and creating all the objects and assigning them is not a feasible option to me.
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 two shown update paths with an existing Profile containing embedded documents, then inspect the from_json and save(validate=False) entry points. Compare the persisted document before and after each path; done means identifying whether the unchanged document is expected or fixing it with a regression test.
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
- 35/100