diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-06-26 02:20:45 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-06-26 02:20:45 +0000 |
| commit | 002dbd16b4453fc9c89533002ab17189a8122e70 (patch) | |
| tree | aab410b9aff0f600f24c98fa732749bb979e1351 | |
| parent | 588eeb356c7a88138fac53c3caeb705e16aa562c (diff) | |
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
| -rw-r--r-- | django/db/models/query.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index d0fae461e9..2e9752288e 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -36,7 +36,7 @@ class CollectedObjects(object): """ 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 @@ class CollectedObjects(object): 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 @@ class CollectedObjects(object): 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 @@ class QuerySet(object): 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 @@ class ValuesQuerySet(QuerySet): # 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() |
