﻿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
20101	bitwise or on queryset fails when using exlude over manytomany	harm	nobody	"== description == 
In the case below, when doing a bitwise `or` of 2 querysets, the results fails silently.

An item that should be in the result, is not.


== steps to reproduce ==

run the following test case


{{{ models.py }}}
{{{
#!python
from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    choices = models.ManyToManyField('Choice', related_name='polls')

        
class Choice(models.Model):
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
}}}


{{{tests.py }}}
{{{
#!python
from django.test import TestCase
    
from models import Poll, Choice
    
class SimpleTest(TestCase):
    def test_or(self):
        """"""
        Tests that querysets can be or-ed
        """"""
        p = Poll.objects.create()

        c1 = Choice.objects.create()
        c2 = Choice.objects.create()
        c3 = Choice.objects.create()


        qs1 = Poll.objects.exclude(choices__in=[c1, c2])
        qs2 = Poll.objects.filter(choices__in=[c3])

        self.assertTrue(p in qs1)
        self.assertFalse(p in qs2)

        # here is the bug,  p is in qs1, but not in the orred result
        self.assertTrue(p in (qs1|qs2))
}}}


== result ==
Test fails
{{{
======================================================================
FAIL: test_or (poll.tests.SimpleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""mysite/poll/tests.py"", line 31, in test_or
    self.assertTrue(p in (qs1|qs2))
AssertionError: False is not True

}}}

== expected result ==
testcase passes


== version ==
found on 1.4.3, same problem exists in 1.5.0
"	Bug	closed	Database layer (models, ORM)	1.4	Normal	fixed			Unreviewed	0	0	0	0	0	0
