Ticket #12870: django-t12870.diff

File django-t12870.diff, 3.4 KB (added by Alex, 5 years ago)

I'm unable to reproduce with these tests.

  • tests/regressiontests/queries/models.py

    diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
    index 43c8437..4f33277 100644
    a b class Note(models.Model): 
    4343        ordering = ['note']
    4444
    4545    def __unicode__(self):
    46         return self.note
     46        return ":".join([self.misc, self.note])
    4747
    4848class Annotation(models.Model):
    4949    name = models.CharField(max_length=10)
    Bugs #2874, #3002 
    648648# This is also a good select_related() test because there are multiple Note
    649649# entries in the SQL. The two Note items should be different.
    650650>>> qs[0].note, qs[0].creator.extra.note
    651 (<Note: n2>, <Note: n1>)
     651(<Note: bar:n2>, <Note: foo:n1>)
    652652
    653653Bug #3037
    654654>>> Item.objects.filter(Q(creator__name='a3', name='two')|Q(creator__name='a4', name='four'))
    True 
    684684
    685685Bug #5261
    686686>>> Note.objects.exclude(Q())
    687 [<Note: n1>, <Note: n2>, <Note: n3>]
     687[<Note: foo:n1>, <Note: bar:n2>, <Note: foo:n3>]
    688688
    689689Bug #3045, #3288
    690690Once upon a time, select_related() with circular relations would loop
    Bug #7107 -- this shouldn't create an infinite loop. 
    897897
    898898Empty querysets can be merged with others.
    899899>>> Note.objects.none() | Note.objects.all()
    900 [<Note: n1>, <Note: n2>, <Note: n3>]
     900[<Note: foo:n1>, <Note: bar:n2>, <Note: foo:n3>]
    901901>>> Note.objects.all() | Note.objects.none()
    902 [<Note: n1>, <Note: n2>, <Note: n3>]
     902[<Note: foo:n1>, <Note: bar:n2>, <Note: foo:n3>]
    903903>>> Note.objects.none() & Note.objects.all()
    904904[]
    905905>>> Note.objects.all() & Note.objects.none()
    relations. 
    10681068[<Annotation: a1>]
    10691069>>> xx = ExtraInfo.objects.create(info='xx', note=n3)
    10701070>>> Note.objects.filter(Q(extrainfo__author=a1)|Q(extrainfo=xx))
    1071 [<Note: n1>, <Note: n3>]
     1071[<Note: foo:n1>, <Note: foo:n3>]
    10721072>>> xx.delete()
    10731073>>> q = Note.objects.filter(Q(extrainfo__author=a1)|Q(extrainfo=xx)).query
    10741074>>> len([x[2] for x in q.alias_map.values() if x[2] == q.LOUTER and q.alias_refcount[x[1]]])
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    index 5699b60..f70fda8 100644
    a b  
    11import unittest
    2 from models import Tag, Annotation
    3 from django.db.models import Count
     2
     3from django.db.models import Count, Q
     4from django.test import TestCase
     5
     6from models import Tag, Annotation, Note
     7
    48
    59class QuerysetOrderedTests(unittest.TestCase):
    610    """
    class QuerysetOrderedTests(unittest.TestCase): 
    2428        qs = Annotation.objects.annotate(num_notes=Count('notes'))
    2529        self.assertEqual(qs.ordered, False)
    2630        self.assertEqual(qs.order_by('num_notes').ordered, True)
    27        
    28  No newline at end of file
     31
     32class ExcludeTestCase(TestCase):
     33    def test_disjunction(self):
     34        pypy = [
     35            Note.objects.create(misc="a%d" % i, note="PyPy!") for i in range(3)
     36        ]
     37        unladen = [
     38            Note.objects.create(misc="a%d" % i, note="Unladen Swallow!")
     39            for i in range(3)
     40        ]
     41        cpython = [
     42            Note.objects.create(misc="a%d" % i, note="CPython!") for i in range(3)
     43        ]
     44       
     45        self.assertEqual(
     46            list(Note.objects.exclude(note="PyPy!").exclude(note="Unladen Swallow!")),
     47            cpython
     48        )
     49        self.assertEqual(
     50            list(Note.objects.exclude(Q(note="PyPy!") | Q(note="Unladen Swallow!"))),
     51            cpython
     52        )
Back to Top