summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-04-04 03:21:31 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-04-04 03:21:31 +0000
commitdded5f52cc1dbe0e58b64a3217e12e72da7bed23 (patch)
tree1c3cc230ff7713ab4bbd7d9da39aaa620e0302c1 /tests/regressiontests
parent19d14509299c641ee44ab0755a6e0f3026e48341 (diff)
Fixed #10695 -- Fixed implementation of deferred attribute retrieval.
The original implementation had a few silly bugs in it that meant that data was not being used only on the instance of the class that it was appropriate for (one of the traps when using class-level things). No more! Thanks to Justin Bronn and Alex Gaynor for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10382 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/defer_regress/models.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/regressiontests/defer_regress/models.py b/tests/regressiontests/defer_regress/models.py
index c46d7ce176..0cd6facff7 100644
--- a/tests/regressiontests/defer_regress/models.py
+++ b/tests/regressiontests/defer_regress/models.py
@@ -6,7 +6,7 @@ from django.conf import settings
from django.db import connection, models
class Item(models.Model):
- name = models.CharField(max_length=10)
+ name = models.CharField(max_length=15)
text = models.TextField(default="xyzzy")
value = models.IntegerField()
other_value = models.IntegerField(default=0)
@@ -14,6 +14,9 @@ class Item(models.Model):
def __unicode__(self):
return self.name
+class RelatedItem(models.Model):
+ item = models.ForeignKey(Item)
+
__test__ = {"regression_tests": """
Deferred fields should really be deferred and not accidentally use the field's
default value just because they aren't passed to __init__.
@@ -39,9 +42,31 @@ True
u"xyzzy"
>>> len(connection.queries) == num + 2 # Effect of text lookup.
True
+>>> obj.text
+u"xyzzy"
+>>> len(connection.queries) == num + 2
+True
>>> settings.DEBUG = False
+Regression test for #10695. Make sure different instances don't inadvertently
+share data in the deferred descriptor objects.
+
+>>> i = Item.objects.create(name="no I'm first", value=37)
+>>> items = Item.objects.only('value').order_by('-value')
+>>> items[0].name
+u'first'
+>>> items[1].name
+u"no I'm first"
+
+>>> _ = RelatedItem.objects.create(item=i)
+>>> r = RelatedItem.objects.defer('item').get()
+>>> r.item_id == i.id
+True
+>>> r.item == i
+True
+
+
+
"""
}
-