mongoengine
mongoengine copied to clipboard
Lazy Reference to Abstract class attempts to obtain the classes `id_field`
This is a similar issue to #837, though pertaining to LazyReferenceField
s as opposed to ReferenceField
s
The following code should enable you to replicate the issue in mongoengine version 0.18.0
import mongoengine as me
class AbstractExample(me.Document):
meta = {"abstract": True}
class ConcreteExample(AbstractExample):
pass
class Referrer(me.Document):
reference = me.LazyReferenceField(AbstractExample)
Saving a Referrer
to the database will trigger a KeyError: id_field
.
Replacing the LazyReferenceField
with a regular ReferenceField
doesn't trigger this exception.
Here's another example, with a self-reference to an abstract class. Here the KeyError: id_field
is thrown in the delete
from mongoengine import *
class B(Document):
a_id = LazyReferenceField('self', reverse_delete_rule=DENY)
meta = {"allow_inheritance": True, "abstract": True}
class C(B):
nc = IntField()
meta = {"allow_inheritance": False, "abstract": False}
connect('test', host='mongomock://localhost')
c1 = C(nc=3).save()
print(f"saved : {c1.to_mongo()}")
c1.delete()
Using mongoengine 0.19.1 , Python 3.7
Perhaps the error is actually allowing references to Abstract classes?
We are also hitting up against this.