Possible bug with GenericRelations and values_list

65 views
Skip to first unread message

Skylar Saveland

unread,
Dec 10, 2012, 8:58:24 PM12/10/12
to django-d...@googlegroups.com
Hi,

I posted this in the django-users group but I think it may merit posting here, as well. I have a test case which I think should pass.


Is this a bug? If so, is it a bug that is not in the tracker?

Thanks,
Skylar

Karen Tracey

unread,
Dec 10, 2012, 11:45:10 PM12/10/12
to django-d...@googlegroups.com

I'd say it's a bug. I can't find an exact match in trac but I'd guess the root cause is similar to what's underlying:

https://code.djangoproject.com/ticket/11387

The SQL for the query in your test case that attempts to fetch the Animal object tags using values_list is:

SELECT "generic_relations_taggeditem"."id" FROM "generic_relations_animal" LEFT OUTER JOIN "generic_relations_taggeditem" ON ("generic_relations_animal"."id" = "generic_relations_taggeditem"."object_id")

This suffers from the same problem as the sql in #11387: it's not including any restriction on content type in the query, thus you can get tags that are pointing to non-Animals.

Karen

Anssi Kääriäinen

unread,
Dec 11, 2012, 9:55:08 AM12/11/12
to Django developers
For what its worth this one should be fixed in the patch for ticket
#10790. After the patch the join condition will know the join field,
and the join field will be asked for extra join sql when generating
the join clause. This way it will be possible to append the content
type restriction into the JOIN clause instead of the WHERE clause.

- Anssi

On 11 joulu, 06:45, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Dec 10, 2012 at 8:58 PM, Skylar Saveland
> <skylar.savel...@gmail.com>wrote:
>
>
>
> > I posted this in the django-users group but I think it may merit posting
> > here, as well. I have a test case which I think should pass.
>
> >https://github.com/skyl/django/commit/556df1c46146c2fc9c4022d838fa23f...
Reply all
Reply to author
Forward
0 new messages