MongoEngine / MongoEngine/mongoengine

Unable to set reverse_delte_rule to GenericReferenceField. AttributeError: 'GenericReferenceField' object has no attribute 'document_type'

Open
#2,308 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

I get the following error when trying to add "reverse_delete_rule=db.CASCADE" to a GenericReferenceField:

AttributeError: 'GenericReferenceField' object has no attribute 'document_type'

This is my code:

`from database.db import db

class Movie(db.DynamicDocument):
name = db.StringField(required=True, unique=True)
casts = db.ListField(db.StringField)
genres = db.ListField(db.StringField)
directors = db.GenericReferenceField(reverse_delete_rule=db.CASCADE)
`

This is the error:
AttributeError: 'GenericReferenceField' object has no attribute 'document_type'

My understanding is that GenericReferenceField inherits ReferenceField attributes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported Movie model with GenericReferenceField(reverse_delete_rule=db.CASCADE), then compare GenericReferenceField with ReferenceField to trace where document_type is expected. Done means the reported AttributeError is resolved and the reverse-delete behavior is covered by a regression test; the issue names no specific files or existing tests.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.