Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Refs #13227 -- Partial backport of r12865; backported the cha…

…nges 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
  • Loading branch information...
commit cf08ea496e9d40f2f5b3677feedb59cd600fab91 1 parent ee2b07c
Russell Keith-Magee authored
6  django/db/models/query_utils.py
@@ -152,7 +152,8 @@ def __init__(self, *args, **kwargs):
152 152
     def _combine(self, other, conn):
153 153
         if not isinstance(other, Q):
154 154
             raise TypeError(other)
155  
-        obj = deepcopy(self)
  155
+        obj = type(self)()
  156
+        obj.add(self, conn)
156 157
         obj.add(other, conn)
157 158
         return obj
158 159
 
@@ -163,7 +164,8 @@ def __and__(self, other):
163 164
         return self._combine(other, self.AND)
164 165
 
165 166
     def __invert__(self):
166  
-        obj = deepcopy(self)
  167
+        obj = type(self)()
  168
+        obj.add(self, self.AND)
167 169
         obj.negate()
168 170
         return obj
169 171
 
8  tests/regressiontests/queries/models.py
@@ -5,6 +5,7 @@
5 5
 import datetime
6 6
 import pickle
7 7
 import sys
  8
+import threading
8 9
 
9 10
 from django.conf import settings
10 11
 from django.db import models
@@ -44,6 +45,13 @@ class Meta:
44 45
     def __unicode__(self):
45 46
         return self.note
46 47
 
  48
+    def __init__(self, *args, **kwargs):
  49
+        super(Note, self).__init__(*args, **kwargs)
  50
+        # Regression for #13227 -- having an attribute that
  51
+        # is unpickleable doesn't stop you from cloning queries
  52
+        # that use objects of that type as an argument.
  53
+        self.lock = threading.Lock()
  54
+
47 55
 class Annotation(models.Model):
48 56
     name = models.CharField(max_length=10)
49 57
     tag = models.ForeignKey(Tag)

0 notes on commit cf08ea4

Please sign in to comment.
Something went wrong with that request. Please try again.