diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-13 02:00:46 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-13 02:00:46 +0000 |
| commit | cf08ea496e9d40f2f5b3677feedb59cd600fab91 (patch) | |
| tree | 6d924bdde5692f596748d2b98edb2523e6cc8962 | |
| parent | ee2b07c7fcf0b7e67029b2f04fe18e369eecf98a (diff) | |
[1.1.X] Refs #13227 -- Partial backport of r12865; backported the changes to Where tree cloning logic to ensure that unclonable objects in a where() clause don't break querying.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12963 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/query_utils.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/queries/models.py | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 5ac08c0619..f6dc533c28 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -152,7 +152,8 @@ class Q(tree.Node): def _combine(self, other, conn): if not isinstance(other, Q): raise TypeError(other) - obj = deepcopy(self) + obj = type(self)() + obj.add(self, conn) obj.add(other, conn) return obj @@ -163,7 +164,8 @@ class Q(tree.Node): return self._combine(other, self.AND) def __invert__(self): - obj = deepcopy(self) + obj = type(self)() + obj.add(self, self.AND) obj.negate() return obj diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index f01e5f2c3e..22ae530613 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -5,6 +5,7 @@ Various complex queries that have been problematic in the past. import datetime import pickle import sys +import threading from django.conf import settings from django.db import models @@ -44,6 +45,13 @@ class Note(models.Model): def __unicode__(self): return self.note + def __init__(self, *args, **kwargs): + super(Note, self).__init__(*args, **kwargs) + # Regression for #13227 -- having an attribute that + # is unpickleable doesn't stop you from cloning queries + # that use objects of that type as an argument. + self.lock = threading.Lock() + class Annotation(models.Model): name = models.CharField(max_length=10) tag = models.ForeignKey(Tag) |
