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
27557a7a
Kaydet (Commit)
27557a7a
authored
Ock 15, 2018
tarafından
hayashi
Kaydeden (comit)
Tim Graham
Ock 17, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28857 -- Fixed invalid SQL when using Cast with complex expressions on PostgreSQL.
üst
b902878f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
comparison.py
django/db/models/functions/comparison.py
+3
-1
test_cast.py
tests/db_functions/test_cast.py
+16
-2
No files found.
django/db/models/functions/comparison.py
Dosyayı görüntüle @
27557a7a
...
...
@@ -21,7 +21,9 @@ class Cast(Func):
def
as_postgresql
(
self
,
compiler
,
connection
):
# CAST would be valid too, but the :: shortcut syntax is more readable.
return
self
.
as_sql
(
compiler
,
connection
,
template
=
'
%(expressions)
s::
%(db_type)
s'
)
# 'expressions' is wrapped in parentheses in case it's a complex
# expression.
return
self
.
as_sql
(
compiler
,
connection
,
template
=
'(
%(expressions)
s)::
%(db_type)
s'
)
class
Coalesce
(
Func
):
...
...
tests/db_functions/test_cast.py
Dosyayı görüntüle @
27557a7a
import
datetime
import
decimal
import
unittest
from
django.db
import
models
from
django.db
import
connection
,
models
from
django.db.models
import
Avg
from
django.db.models.expressions
import
Value
from
django.db.models.functions
import
Cast
from
django.test
import
TestCase
,
ignore_warnings
,
skipUnlessDBFeature
from
django.test
import
(
TestCase
,
ignore_warnings
,
override_settings
,
skipUnlessDBFeature
,
)
from
.models
import
Author
...
...
@@ -60,3 +64,13 @@ class CastTests(TestCase):
cast_float
=
numbers
.
get
()
.
cast_float
self
.
assertIsInstance
(
cast_float
,
float
)
self
.
assertEqual
(
cast_float
,
0.125
)
@unittest.skipUnless
(
connection
.
vendor
==
'postgresql'
,
'PostgreSQL test'
)
@override_settings
(
DEBUG
=
True
)
def
test_expression_wrapped_with_parentheses_on_postgresql
(
self
):
"""
The SQL for the Cast expression is wrapped with parentheses in case
it's a complex expression.
"""
list
(
Author
.
objects
.
annotate
(
cast_float
=
Cast
(
Avg
(
'age'
),
models
.
FloatField
())))
self
.
assertIn
(
'(AVG("db_functions_author"."age"))::double precision'
,
connection
.
queries
[
-
1
][
'sql'
])
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