Wednesday, October 1, 2014

Handling circular references in recursive foreign keys

Django users:

I'm currently trying to deal with something that works just fine in PSQL but causes django some headaches. I have a model like this:

class Application(models.Model):
    ... #other stuff
    paired_with_app = models.ForeignKey(
        'Application',
        blank=True,
        null=True,
    )

Everything works great in SQL and in django until I get two rows that use this foreign key to refer to each other. When this happens, any query involving a row involved in a circular reference takes 6 seconds longer and spits out the python "avoid infinite recursion" error message,

"Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in <type 'exceptions.RuntimeError'> ignored"

How do I get django to tolerate the circular reference without trying to follow it ad infinitum? All of the code we use it for doesn't follow any references, which means that we're currently setting this foreign key field to the IntegerField "paired_with_app_id" as a workaround.

Thanks,

--

Jorge

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/57e1e9bc-5ed3-4500-b78f-4cb854935614%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment