﻿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
19982	Chained Queryset filters generate wrong join with reverse relations	fhahn		"Chaining {{{.filter()}}} on a Queryset can have a different result than one {{{.filter()}}} with all the attributes of the chained filters.

eg:
{{{        
        n1 = Note.objects.create(note='n1', misc='foo', id=1)
        n2 = Note.objects.create(note='n2', misc='bar', id=2)

        a1 = Author.objects.create(name='a1')
        a3 = Author.objects.create(name='a3')
        Item.objects.create(name='i1', note=n1, creator=a1)
        Item.objects.create(name='i3', note=n1, creator=a3)

    Note.objects.filter(item__creator=a1).filter(item__name='i3') != Note.objects.filter(item__creator=a1, item__name='i3')
}}}

I think in this case, when chaining {{{ .filter() }}}, another JOIN for {{{ item }}} is added instead of reusing the previous JOIN.

I've created a test for this issue on Github: https://github.com/fhahn/django/commit/85554864c7f94546e9b663c2743e07a154c4f301"	Bug	closed	Database layer (models, ORM)	dev	Normal	duplicate		flo@…	Unreviewed	0	0	0	0	0	0
