Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chavus opened this issue Apr 23, 2020 · 2 comments

Comments

@chavus
Copy link

chavus commented Apr 23, 2020

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.

@chavus chavus changed the title Unable to define reverse_delte_rule to GenericReferenceField. AttributeError: 'GenericReferenceField' object has no attribute 'document_type' Unable to set reverse_delte_rule to GenericReferenceField. AttributeError: 'GenericReferenceField' object has no attribute 'document_type' Apr 23, 2020
@softwolves
Copy link

its not working ,u can use numbers 0.,1,2,3,4

@combscCode
Copy link

GenericReferenceField does not inherit from ReferenceField. Currently MongoEngine does not support reverse delete rules for GenericReferenceField.

This could be fixed in multiple ways, either by having GenericReferenceField check every defined Document upon deletion (expensive and honestly not sure if this feature should be given to users given the performance concerns) or by allowing reverse delete rules when the GenericReferenceField defines a set of choices for documents it can reference, then checking that smaller set of document upon delete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants