Maybe it's a variant of #3045 bug.
The [simplified] case is
class Foo(models.Model):
parent = models.ForeignKey('self')
class Meta:
db_table = 'foos'
foo = Foo.objects.select_related().get(pk=1)
That leads to infinite recursion in django.db.models.query.fill_table_cache. The bottom of the stack trace is:
........ many many lines ............
File "/home/maxim/dproject/django/db/models/query.py", line 684, in fill_table_cache
fill_table_cache(f.rel.to._meta, select, tables, where, db_table, cache_tables_seen)
File "/home/maxim/dproject/django/db/models/query.py", line 684, in fill_table_cache
fill_table_cache(f.rel.to._meta, select, tables, where, db_table, cache_tables_seen)
File "/home/maxim/dproject/django/db/models/query.py", line 681, in fill_table_cache
where.append('%s.%s = %s.%s' % \
File "/home/maxim/dproject/django/db/models/fields/related.py", line 737, in get_related_field
return self.to._meta.get_field(self.field_name)
File "/home/maxim/dproject/django/db/models/options.py", line 98, in get_field
if f.name == name:
RuntimeError: maximum recursion depth exceeded in cmp