MongoEngine / MongoEngine/mongoengine
delete rule set in abstract-document fails
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
I had a class something like this:
class Person(Document):
name = StringField(verbose_name="Name")
class AbstractAddress(DynamicDocument):
meta = {
"abstract": True
}
person_ref = ReferenceField(Person, required=True, reverse_delete_rule=CASCADE)
class RealAddress(AbstractAddress):
// stuff
The following code gives an error:
p = someperson
p.delete()
# AttributeError: type object 'AbstractAddress' has no attribute 'objects'
# **filename*** in **methodname**
#
# p.delete()
#
# ...
#
# ▶ Local vars
# /usr/local/lib/python2.7/dist-packages/mongoengine/document.py in delete
#
# self._qs.filter(**self._object_key).delete(write_concern=write_concern, _from_doc_delete=True)
#
# ...
#
# ▶ Local vars
# /usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py in delete
#
# ref_q = document_cls.objects(**{field_name + '__in': self})
#
# ...
Note: i juggled some names around,, but you get the idea :)
When I define the ReferenceField in the non-abstract class the delete() call works
-- mongoengine installed using pip, its 0.8.7.
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 failure in mongoengine/document.py through the delete path shown in mongoengine/queryset/base.py. Check how the abstract AbstractAddress reference is resolved during Person deletion, then verify that deleting a Person with the inherited reference no longer raises AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100