MongoEngine / MongoEngine/mongoengine
Bugs when deleting dynamic attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
There is already a ticket regarding reloading bugs (https://github.com/MongoEngine/mongoengine/issues/1050), but here it's more precisely the erasing of dynamic attributes which seems faulty, whatever the method used.
Update(), modify() and "del+save" all behave contrary to expectations, which would be to have extra_arg disappear completely from object.
The only workaround we found was to update() and then reload entirely the object from DB, with a MyDocument.objects.get(pk).
import mongoengine as mongo
class MyDocument(mongo.DynamicDocument):
label = mongo.StringField(required=True)
document = MyDocument(
label='testage',
extra_arg=33 # this attribute doesn't exist in schema
)
document.save()
assert document.pk, document.pk
assert document.label == 'testage'
assert document.extra_arg == 33
document.modify(label='testage_bis')
assert document.label == 'testage_bis'
document.update(label='testage_ter')
assert document.label == 'testage_bis' # obsolete
document.reload()
assert document.label == 'testage_ter' # well updated
assert document.extra_arg == 33
document.update(unset__extra_arg=1)
document.reload()
assert document.extra_arg == 33 # ????? should be AttributeError
del document.extra_arg
document.save()
assert document.extra_arg is None # ????? should be AttributeError
document.extra_arg = 34
document.save()
document.modify(unset__extra_arg=1) # ???? explodes with KeyError: 'extra_arg'
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 the supplied DynamicDocument reproduction and trace the update(), modify(), save(), reload(), and dynamic-attribute deletion behavior. Add regression coverage for unset and deleted attributes, including the reported KeyError, and consider the issue done when the attribute is removed consistently from the object and database without errors.
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
- 42/100