﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17014	prefetch_related infinite recursion by default managers	Anssi Kääriäinen	nobody	"I haven't tested these two cases with the trunk version, so I don't know if these mentioned problems work with prefetch_related or not. At least both of these need tests, though.

Recursive default queryset prefetch_related calls need test. The simplest case is:

{{{
class PeopleDefManager(models.Manager):
    def get_query_set(self):
        return super(PeopleDefmanager, self).get_query_set().prefetch_related('reverse_best_friend')

class People(models.Model):
    name = models.TextField()
    best_friend = models.ForeignKey('self', related_name='reverse_best_friend')
    objects = PeopleDefManager()
}}}

I did some work for #17000, and my version for that ticket had a very serious problem. The problem was indefinite recursion which ended up eating all the memory and going to OOM killer. That is a pretty bad failure condition... I ended up tracking which prefetches had been done and bailing out if recursion was detected. And having a hard limit of doing at most 200 prefetch_one_level calls in one queryset. The limit could be much lower while still allowing for infinite recursion. I haven't tested if the trunk version suffers from this. At least tests needed in any case.

Another condition that needs testing is:
{{{
                  A
                 / \
       through  /   \    through
       b_set   /     \   c_set
              B       C
               \     /
  through d_set \   /    through d_set
                 \ /
                  D
}}}

It is important that both B and C have a field with same name to D. I don't know if this works or not, but this also needs tests at least."	Bug	closed	Database layer (models, ORM)	1.3	Normal	fixed		anssi.kaariainen@…	Accepted	0	1	0	0	0	0
