﻿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
30482	prefetch_related_objects evaluates queryset when checking for invalid prefetch ordering.	Iain P. Watts	Iain P. Watts	"When encountering a prefetch it has already seen and checking whether to throw the ""lookup was already seen with a different queryset"" ValueError, prefetch_related_objects will inadvertently evaluate lookup.queryset. For example:

{{{
foo = Foo.objects.create()
prefetches = [
    'bar',
    Prefetch('bar', queryset=Bar.objects.filter(my_field=True))
]
prefetch_related_objects([foo], *prefetches)
}}}
Right before it throws the ValueError, the above code will execute the full unfiltered query `Bar.objects.filter(my_field=True)`. This may match a very large number of rows (or a whole table), since it is not restricted to `Bars` related to the specific `foo`. In our case this led to the query timing out and the page returning a 504 without the code ever actually reaching the ValueError."	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	1	0	0	0	0	0
