Opened 8 years ago

Closed 8 years ago

#3764 closed (duplicate)

select_related() raises RuntimeError with ForeignKey('self') when record linked to itself

Reported by: anonymous Owned by: adrian
Component: Database layer (models, ORM) Version: master
Severity: Keywords: select_related, admin, maximum recursion, ForeignKey
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

class Person(models.Model):
    name = models.CharField(maxlength=100)
    advocate = models.ForeignKey('self', null = False, related_name = 'customers')

person = Person.objects.create(name="First", advocate_id = 0)
person.save()
person.advocate = person
person.save()

Then

Person.objects.all().select_related()

will raise RuntimeException: maximum recursion depth exceeded in cmp

Admin are of web-site also becomes frozen when you try to open 'Persons' page

Change History (1)

comment:1 Changed 8 years ago by (removed)

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

This is a duplicate of 3288 (which is reviewed/accepted).

Note: See TracTickets for help on using tickets.
Back to Top