﻿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
17600	Error in encapsulates filters (Q)	Pablo Martín	nobody	"If I have the next code:

{{{
   class A(models.Model):

       .....

    class B(models.Model):

        a = models.ManyToManyField(A)

}}}
The next queries get differents results:


{{{
    B.objects.exclude(a__in=[7])

    from django.db.models import Q
    B.objects.exclude(Q(a__in=[7]))
}}}

Results:

The first query get all objects excluding the ""b objects"" with a=7. It's Ok
But the second query get all objects excluding the ""b objects"" with a=7 or a=None.
Is it an error?, Is it known?

I add a verbose example, execute the next code

{{{
    from django.contrib.auth.models import User, Group
    u1 = User.objects.create(username='u1')
    u2 = User.objects.create(username='u2')
    u3 = User.objects.create(username='u3')
    g1 = Group.objects.create(name='g1')
    g2 = Group.objects.create(name='g2')
    u1.groups.add(g1)
    u2.groups.add(g2)
    print User.objects.exclude(groups__in=[g1.pk])
    print User.objects.exclude(Q(groups__in=[g1.pk]))
}}}

I have seen the [https://docs.djangoproject.com/en/dev/topics/db/queries/ documentation] and the [https://code.djangoproject.com/browser/django/trunk/tests/modeltests/or_lookups/tests.py tests] and I didn't see any note or reference"	Bug	closed	Database layer (models, ORM)	1.3	Normal	fixed		anssi.kaariainen@… Gabe Jackson	Ready for checkin	1	0	0	0	0	0
