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
5778b570
Kaydet (Commit)
5778b570
authored
Kas 05, 2017
tarafından
Tim Martin
Kaydeden (comit)
Tim Graham
Ara 26, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28731 -- Added an error message when using an empty Q() in a When expression.
Otherwise it generates invalid SQL.
üst
6deaddcc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
0 deletions
+7
-0
expressions.py
django/db/models/expressions.py
+2
-0
tests.py
tests/expressions_case/tests.py
+5
-0
No files found.
django/db/models/expressions.py
Dosyayı görüntüle @
5778b570
...
...
@@ -818,6 +818,8 @@ class When(Expression):
condition
,
lookups
=
Q
(
**
lookups
),
None
if
condition
is
None
or
not
getattr
(
condition
,
'conditional'
,
False
)
or
lookups
:
raise
TypeError
(
"__init__() takes either a Q object or lookups as keyword arguments"
)
if
isinstance
(
condition
,
Q
)
and
not
condition
:
raise
ValueError
(
"An empty Q() can't be used as a When() condition."
)
super
()
.
__init__
(
output_field
=
None
)
self
.
condition
=
condition
self
.
result
=
self
.
_parse_expressions
(
then
)[
0
]
...
...
tests/expressions_case/tests.py
Dosyayı görüntüle @
5778b570
...
...
@@ -1301,3 +1301,8 @@ class CaseWhenTests(SimpleTestCase):
When
(
condition
=
object
())
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
When
()
def
test_empty_q_object
(
self
):
msg
=
"An empty Q() can't be used as a When() condition."
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
When
(
Q
(),
then
=
Value
(
True
))
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