﻿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
17991	Prefetch_related fails with GenericRelation	okke@…	nobody	"While greatly anticipating prefetch_related, I am sorry to say that bug #17838 is not yet entirely fixed. I am running into empty result sets when I perform a prefetch_related.

I have a GenericRelation on my model to Comments. My model uses an integer primary key. This combination makes the prefetch_related return empty embedded result sets.

In the latest django, django/db/models/query.py, line 1791, the _prefetched_objects_cache is ''accessed'' with (possibly) an integer as value. However, the _prefetched_objects_cache is always ''populated'' with unicode values (lines 1770 - 1774)

The quick fix is to replace (line 1791)

{{{
            obj._prefetched_objects_cache[cache_name] = qs
}}}

with 
{{{ 
            obj._prefetched_objects_cache[unicode(cache_name)] = qs
}}}

Can someone create a patch for this, and write a test to see if the queryset is actually populated with related items?
"	Bug	closed	Database layer (models, ORM)	1.4	Normal	fixed		lemaire.adrien@…	Accepted	1	0	0	1	0	0
