Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed the bulk of the sanity checking when merging QuerySets.

It was causing too many inconvenient and unintended problems when merging
legitimate subclasses (e.g. with geo-django classes). There's still a hook
there that we use when merging ValueQuerySets, but if you try to merge two
disparate QuerySets and it breaks all that happens is you get to keep both
pieces. We're no longer penalising the useful usages just for the people who
aren't concentrating.

Fixed #7113.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7742 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 002dbd16b4453fc9c89533002ab17189a8122e70 1 parent 588eeb3
@malcolmt malcolmt authored
Showing with 9 additions and 9 deletions.
  1. +9 −9 django/db/models/query.py
View
18 django/db/models/query.py
@@ -36,7 +36,7 @@ def add(self, model, pk, obj, parent_model, nullable=False):
"""
Adds an item.
model is the class of the object being added,
- pk is the primary key, obj is the object itself,
+ pk is the primary key, obj is the object itself,
parent_model is the model of the parent object
that this object was reached through, nullable should
be True if this relation is nullable.
@@ -77,7 +77,7 @@ def keys(self):
def ordered_keys(self):
"""
- Returns the models in the order that they should be
+ Returns the models in the order that they should be
dealth with i.e. models with no dependencies first.
"""
dealt_with = SortedDict()
@@ -92,7 +92,7 @@ def ordered_keys(self):
found = True
if not found:
raise CyclicDependency("There is a cyclic dependency of items to be processed.")
-
+
return dealt_with.keys()
def unordered_keys(self):
@@ -583,11 +583,11 @@ def _fill_cache(self, num=None):
def _merge_sanity_check(self, other):
"""
- Checks that we are merging two comparable queryset classes.
+ Checks that we are merging two comparable queryset classes. By default
+ this does nothing, but see the ValuesQuerySet for an example of where
+ it's useful.
"""
- if self.__class__ is not other.__class__:
- raise TypeError("Cannot merge querysets of different types ('%s' and '%s'."
- % (self.__class__.__name__, other.__class__.__name__))
+ pass
class ValuesQuerySet(QuerySet):
def __init__(self, *args, **kwargs):
@@ -599,7 +599,7 @@ def __init__(self, *args, **kwargs):
# names of the model fields to select.
def iterator(self):
- if (not self.extra_names and
+ if (not self.extra_names and
len(self.field_names) != len(self.model._meta.fields)):
self.query.trim_extra_select(self.extra_names)
names = self.query.extra_select.keys() + self.field_names
@@ -773,7 +773,7 @@ def delete_objects(seen_objs):
except CyclicDependency:
# if there is a cyclic dependency, we cannot in general delete
# the objects. However, if an appropriate transaction is set
- # up, or if the database is lax enough, it will succeed.
+ # up, or if the database is lax enough, it will succeed.
# So for now, we go ahead and try anway.
ordered_classes = seen_objs.unordered_keys()
Please sign in to comment.
Something went wrong with that request. Please try again.