[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
This commit is contained in:
Russell Keith-Magee 2010-04-13 02:00:46 +00:00
parent ee2b07c7fc
commit cf08ea496e
2 changed files with 12 additions and 2 deletions

View File

@ -152,7 +152,8 @@ class Q(tree.Node):
def _combine(self, other, conn): def _combine(self, other, conn):
if not isinstance(other, Q): if not isinstance(other, Q):
raise TypeError(other) raise TypeError(other)
obj = deepcopy(self) obj = type(self)()
obj.add(self, conn)
obj.add(other, conn) obj.add(other, conn)
return obj return obj
@ -163,7 +164,8 @@ class Q(tree.Node):
return self._combine(other, self.AND) return self._combine(other, self.AND)
def __invert__(self): def __invert__(self):
obj = deepcopy(self) obj = type(self)()
obj.add(self, self.AND)
obj.negate() obj.negate()
return obj return obj

View File

@ -5,6 +5,7 @@ Various complex queries that have been problematic in the past.
import datetime import datetime
import pickle import pickle
import sys import sys
import threading
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
@ -44,6 +45,13 @@ class Note(models.Model):
def __unicode__(self): def __unicode__(self):
return self.note 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): class Annotation(models.Model):
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
tag = models.ForeignKey(Tag) tag = models.ForeignKey(Tag)