Ticket #11319: t11319-r11007.diff

File t11319-r11007.diff, 2.3 KB (added by Russell Keith-Magee, 15 years ago)

Regression tests demonstrating problem

  • tests/modeltests/custom_pk/models.py

    diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py
    index b88af16..a4b0fea 100644
    a b DoesNotExist: Employee matching query does not exist.  
    133133...        print "Fail with %s" % type(e)
    134134Pass
    135135
    136 # Regression for #10785 -- Custom fields can be used for primary keys.
     136# Regression for #10785, #11319 -- Custom fields can be used for primary keys.
    137137>>> new_bar = Bar.objects.create()
    138138>>> new_foo = Foo.objects.create(bar=new_bar)
    139139
    140 # FIXME: This still doesn't work, but will require some changes in
    141 # get_db_prep_lookup to fix it.
    142 # >>> f = Foo.objects.get(bar=new_bar.pk)
    143 # >>> f == new_foo
    144 # True
    145 # >>> f.bar == new_bar
    146 # True
     140>>> f = Foo.objects.get(bar=new_bar.pk)
     141>>> f == new_foo
     142True
     143>>> f.bar == new_bar
     144True
    147145
    148146>>> f = Foo.objects.get(bar=new_bar)
    149147>>> f == new_foo
  • tests/regressiontests/queries/models.py

    diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
    index 0d28926..2525530 100644
    a b class Plaything(models.Model):  
    271271    def __unicode__(self):
    272272        return self.name
    273273
     274# Recursive ForeignKey using "to_field".
     275class Node(models.Model):
     276    num = models.IntegerField(unique=True)
     277    parent = models.ForeignKey("self", to_field="num", null=True)
     278
     279    def __unicode__(self):
     280        return unicode(self.num)
    274281
    275282__test__ = {'API_TESTS':"""
    276283>>> generic = NamedCategory.objects.create(name="Generic")
    True  
    11731180>>> subq._result_cache is None
    11741181True
    11751182
     1183Filtering against a related object must use the to_field value, if it exists,
     1184not the pk (bug #11319).
     1185>>> a1 = Author.objects.get(name="a1")
     1186>>> Report.objects.filter(creator=a1)
     1187[<Report: r1>]
     1188>>> Author.objects.filter(report=r1)
     1189[<Author: a1>]
     1190
     1191>>> node1 = Node.objects.create(num=42)
     1192>>> node2 = Node.objects.create(num=1, parent=node1)
     1193>>> Node.objects.filter(node=node2).query.as_sql()
     1194>>> Node.objects.filter(node=node2)
     1195[<Node: 42>]
     1196>>> Node.objects.filter(parent=node1)
     1197[<Node: 1>]
     1198
    11761199"""}
    11771200
    11781201# In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__
    Using an empty generator expression as the rvalue for an "__in" lookup is legal  
    12411264[]
    12421265
    12431266"""
     1267
Back to Top