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

Maximum recursion exceeded with a ReferenceField('self') in Document #20

Closed
Karmak23 opened this issue Jul 30, 2013 · 1 comment
Closed

Comments

@Karmak23
Copy link

Hi,

We encounter a crash with the following code:

in models:

class Tag(Document):
    name     = StringField(verbose_name=_(u'name'), unique=True)
    slug     = StringField(verbose_name=_(u'slug'))
    language = StringField(verbose_name=_(u'language'), default='')
    parents  = ListField(ReferenceField('self'), default=list)
    children = ListField(ReferenceField('self'), default=list)
    origin   = GenericReferenceField(verbose_name=_(u'Origin'),
                                     help_text=_(u'Initial origin from where '
                                     u'the tag was created from, to eventually '
                                     u'help defining other attributes.'))
    duplicate_of = ReferenceField('Tag', verbose_name=_(u'Duplicate of'),
                                  help_text=_(u'Put a "master" tag here to '
                                  u'help avoiding too much different tags '
                                  u'(eg. singular and plurals) with the same '
                                  u'meaning and loss of information.'))

    meta = {
        'indexes': ['name', ]
    }

in admin.py:

class TagAdmin(admin.DocumentAdmin):

    list_display = ('id', 'name', 'language', 'duplicate_of', )
    list_display_links = ('id', 'name', )
    search_fields = ('name', 'slug', 'duplicate_of', )
    change_list_filter_template = "admin/filter_listing.html"


admin.site.register(Tag, TagAdmin)

Stacktrace of the crash. If I change the referencefield of the duplicate_of attribute to 'self' instead of 'Tag', I get another stacktrace crash, but I think it's basically the same problem.

It doesn't occur if I use ListField(ReferenceField(… [same content]…)), but obviously I do not want to use a list.

Any hint on this one ?

regards,

@jschrewe
Copy link
Owner

You can either use the newest github version of mongodbforms or fix it yourself by changing the last if statement in _setup_document_fields in documentoptions.py to:

if isinstance(f, ReferenceField) and not isinstance(f.document_type._meta, DocumentMetaWrapper) \
        and self.document != f.document_type:
    f.document_type._meta = DocumentMetaWrapper(f.document_type)

A new version of mongodbforms is coming, but there is one more bug that needs fixing and some thought before.

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

2 participants