Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
b86bb478
Kaydet (Commit)
b86bb478
authored
Ock 14, 2019
tarafından
Sergey Fedoseev
Kaydeden (comit)
Tim Graham
Ock 14, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #30093 -- Fixed ordering of combined queryset ordered by F expressions.
üst
b2c598e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
compiler.py
django/db/models/sql/compiler.py
+3
-4
test_qs_combinators.py
tests/queries/test_qs_combinators.py
+5
-0
No files found.
django/db/models/sql/compiler.py
Dosyayı görüntüle @
b86bb478
...
...
@@ -339,8 +339,9 @@ class SQLCompiler:
seen
=
set
()
for
expr
,
is_ref
in
order_by
:
resolved
=
expr
.
resolve_expression
(
self
.
query
,
allow_joins
=
True
,
reuse
=
None
)
if
self
.
query
.
combinator
:
src
=
expr
.
get_source_expressions
()[
0
]
src
=
resolved
.
get_source_expressions
()[
0
]
# Relabel order by columns to raw numbers if this is a combined
# query; necessary since the columns can't be referenced by the
# fully qualified name and the simple column names may collide.
...
...
@@ -350,12 +351,10 @@ class SQLCompiler:
elif
col_alias
:
continue
if
src
==
sel_expr
:
expr
.
set_source_expressions
([
RawSQL
(
'
%
d'
%
(
idx
+
1
),
())])
resolved
.
set_source_expressions
([
RawSQL
(
'
%
d'
%
(
idx
+
1
),
())])
break
else
:
raise
DatabaseError
(
'ORDER BY term does not match any column in the result set.'
)
resolved
=
expr
.
resolve_expression
(
self
.
query
,
allow_joins
=
True
,
reuse
=
None
)
sql
,
params
=
self
.
compile
(
resolved
)
# Don't add the same column twice, but the order direction is
# not taken into account so we strip it. When this entire method
...
...
tests/queries/test_qs_combinators.py
Dosyayı görüntüle @
b86bb478
...
...
@@ -110,6 +110,11 @@ class QuerySetSetOperationTests(TestCase):
qs2
=
Number
.
objects
.
filter
(
num__gte
=
2
,
num__lte
=
3
)
self
.
assertNumbersEqual
(
qs1
.
union
(
qs2
)
.
order_by
(
'-num'
),
[
3
,
2
,
1
,
0
])
def
test_ordering_by_f_expression
(
self
):
qs1
=
Number
.
objects
.
filter
(
num__lte
=
1
)
qs2
=
Number
.
objects
.
filter
(
num__gte
=
2
,
num__lte
=
3
)
self
.
assertNumbersEqual
(
qs1
.
union
(
qs2
)
.
order_by
(
F
(
'num'
)
.
desc
()),
[
3
,
2
,
1
,
0
])
def
test_union_with_values
(
self
):
ReservedName
.
objects
.
create
(
name
=
'a'
,
order
=
2
)
qs1
=
ReservedName
.
objects
.
all
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment