Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/releases/6.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@ Models
primary key when a ``QuerySet``'s ordering has been forcibly cleared by
calling :meth:`~.QuerySet.order_by` with no arguments.

* As default model ordering is now applied to combined querysets,
:meth:`~.QuerySet.union`, :meth:`~.QuerySet.difference`, and
:meth:`~.QuerySet.intersection` raise ``DatabaseError`` when a field in
:attr:`.Options.ordering` isn't selected by :meth:`~.QuerySet.values` or
:meth:`~.QuerySet.values_list`. Call :meth:`~.QuerySet.order_by` without
arguments before combining to clear the default ordering.

* SQL ``SELECT`` aliases originating from :meth:`.QuerySet.annotate`
calls as well as table and ``JOIN`` aliases are now systematically quoted to
prevent special character collisions. Because quoted aliases are
Expand Down
11 changes: 11 additions & 0 deletions tests/queries/test_qs_combinators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Article,
Author,
Celebrity,
Cover,
ExtraInfo,
Note,
Number,
Expand Down Expand Up @@ -756,6 +757,16 @@ def test_order_raises_on_non_selected_column(self):
# switched order, now 'exists' again:
list(qs2.union(qs1).order_by("num"))

def test_order_by_non_selected_column_from_default_ordering(self):
qs = Cover.objects.values("title")
msg = "ORDER BY term does not match any column in the result set"
with self.assertRaisesMessage(DatabaseError, msg):
list(qs.union(qs))
with self.assertRaisesMessage(DatabaseError, msg):
list(qs.intersection(qs))
with self.assertRaisesMessage(DatabaseError, msg):
list(qs.difference(qs))

@skipUnlessDBFeature("supports_select_difference", "supports_select_intersection")
def test_qs_with_subcompound_qs(self):
qs1 = Number.objects.all()
Expand Down
Loading