MongoEngine / mongoengine

A Python Object-Document-Mapper for working with MongoDB
http://mongoengine.org
MIT License
4.24k stars 1.23k forks source link

Cannot handle indexes on GenericReferenceField #2628

Open fredley opened 2 years ago

fredley commented 2 years ago

A document with the following structure will crash MongoEngine 0.24.0

class MyDoc(Document):
    fld = GenericReferenceField()
    meta = {
            "indexes": [{"fields": ["fld._ref.$id"]}]
    }

This type of index was fine before, but now throws an error:

...
File ".../mongoengine/base/metaclasses.py", line 370, in __new__
    meta["index_specs"] = new_class._build_index_specs(meta["indexes"])
  File ".../mongoengine/base/document.py", line 848, in _build_index_specs
    index_specs = [cls._build_index_spec(spec) for spec in meta_indexes]
  File ".../mongoengine/base/document.py", line 848, in <listcomp>
    index_specs = [cls._build_index_spec(spec) for spec in meta_indexes]
  File ".../mongoengine/base/document.py", line 941, in _build_index_spec
    fields = cls._lookup_field(parts)
  File ".../mongoengine/base/document.py", line 1143, in _lookup_field
    raise LookUpError(
mongoengine.errors.LookUpError: Cannot perform join in mongoDB: fld___ref__$id
JoJoRippling commented 2 years ago

Any finds or solutions on this?