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
be9d6453
Kaydet (Commit)
be9d6453
authored
May 11, 2015
tarafından
Anssi Kääriäinen
Kaydeden (comit)
Tim Graham
May 11, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24766 -- Added join promotion for Case expressions
üst
8e86d9d3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
1 deletion
+42
-1
query_utils.py
django/db/models/query_utils.py
+6
-1
1.8.2.txt
docs/releases/1.8.2.txt
+4
-0
tests.py
tests/expressions_case/tests.py
+32
-0
No files found.
django/db/models/query_utils.py
Dosyayı görüntüle @
be9d6453
...
@@ -87,7 +87,12 @@ class Q(tree.Node):
...
@@ -87,7 +87,12 @@ class Q(tree.Node):
return
clone
return
clone
def
resolve_expression
(
self
,
query
=
None
,
allow_joins
=
True
,
reuse
=
None
,
summarize
=
False
,
for_save
=
False
):
def
resolve_expression
(
self
,
query
=
None
,
allow_joins
=
True
,
reuse
=
None
,
summarize
=
False
,
for_save
=
False
):
clause
,
_
=
query
.
_add_q
(
self
,
reuse
,
allow_joins
=
allow_joins
)
# We must promote any new joins to left outer joins so that when Q is
# used as an expression, rows aren't filtered due to joins.
joins_before
=
query
.
tables
[:]
clause
,
joins
=
query
.
_add_q
(
self
,
reuse
,
allow_joins
=
allow_joins
)
joins_to_promote
=
[
j
for
j
in
joins
if
j
not
in
joins_before
]
query
.
promote_joins
(
joins_to_promote
)
return
clause
return
clause
@classmethod
@classmethod
...
...
docs/releases/1.8.2.txt
Dosyayı görüntüle @
be9d6453
...
@@ -13,3 +13,7 @@ Bugfixes
...
@@ -13,3 +13,7 @@ Bugfixes
* Fixed crash when reusing the same ``Case`` instance in a query
* Fixed crash when reusing the same ``Case`` instance in a query
(:ticket:`24752`).
(:ticket:`24752`).
* Corrected join promotion for ``Case`` expressions. For example, annotating a
query with a ``Case`` expression could unexpectedly filter out results
(:ticket:`24766`).
tests/expressions_case/tests.py
Dosyayı görüntüle @
be9d6453
...
@@ -1016,6 +1016,38 @@ class CaseExpressionTests(TestCase):
...
@@ -1016,6 +1016,38 @@ class CaseExpressionTests(TestCase):
transform
=
attrgetter
(
'integer'
,
'test'
)
transform
=
attrgetter
(
'integer'
,
'test'
)
)
)
def
test_join_promotion
(
self
):
o
=
CaseTestModel
.
objects
.
create
(
integer
=
1
,
integer2
=
1
,
string
=
'1'
)
# Testing that:
# 1. There isn't any object on the remote side of the fk_rel
# relation. If the query used inner joins, then the join to fk_rel
# would remove o from the results. So, in effect we are testing that
# we are promoting the fk_rel join to a left outer join here.
# 2. The default value of 3 is generated for the case expression.
self
.
assertQuerysetEqual
(
CaseTestModel
.
objects
.
filter
(
pk
=
o
.
pk
)
.
annotate
(
foo
=
Case
(
When
(
fk_rel__pk
=
1
,
then
=
2
),
default
=
3
,
output_field
=
models
.
IntegerField
()
),
),
[(
o
,
3
)],
lambda
x
:
(
x
,
x
.
foo
)
)
# Now 2 should be generated, as the fk_rel is null.
self
.
assertQuerysetEqual
(
CaseTestModel
.
objects
.
filter
(
pk
=
o
.
pk
)
.
annotate
(
foo
=
Case
(
When
(
fk_rel__isnull
=
True
,
then
=
2
),
default
=
3
,
output_field
=
models
.
IntegerField
()
),
),
[(
o
,
2
)],
lambda
x
:
(
x
,
x
.
foo
)
)
class
CaseDocumentationExamples
(
TestCase
):
class
CaseDocumentationExamples
(
TestCase
):
@classmethod
@classmethod
...
...
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