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
741ce81a
Kaydet (Commit)
741ce81a
authored
Şub 14, 2019
tarafından
Hasan Ramezani
Kaydeden (comit)
Tim Graham
Şub 14, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29619 -- Added field names to some FieldErrors.
üst
5013d383
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
9 deletions
+38
-9
compiler.py
django/db/models/sql/compiler.py
+16
-4
tests.py
tests/expressions/tests.py
+2
-1
tests.py
tests/expressions_window/tests.py
+10
-2
tests.py
tests/update/tests.py
+10
-2
No files found.
django/db/models/sql/compiler.py
Dosyayı görüntüle @
741ce81a
...
@@ -1191,9 +1191,15 @@ class SQLInsertCompiler(SQLCompiler):
...
@@ -1191,9 +1191,15 @@ class SQLInsertCompiler(SQLCompiler):
'can only be used to update, not to insert.'
%
(
value
,
field
)
'can only be used to update, not to insert.'
%
(
value
,
field
)
)
)
if
value
.
contains_aggregate
:
if
value
.
contains_aggregate
:
raise
FieldError
(
"Aggregate functions are not allowed in this query"
)
raise
FieldError
(
'Aggregate functions are not allowed in this query '
'(
%
s=
%
r).'
%
(
field
.
name
,
value
)
)
if
value
.
contains_over_clause
:
if
value
.
contains_over_clause
:
raise
FieldError
(
'Window expressions are not allowed in this query.'
)
raise
FieldError
(
'Window expressions are not allowed in this query (
%
s=
%
r).'
%
(
field
.
name
,
value
)
)
else
:
else
:
value
=
field
.
get_db_prep_save
(
value
,
connection
=
self
.
connection
)
value
=
field
.
get_db_prep_save
(
value
,
connection
=
self
.
connection
)
return
value
return
value
...
@@ -1356,9 +1362,15 @@ class SQLUpdateCompiler(SQLCompiler):
...
@@ -1356,9 +1362,15 @@ class SQLUpdateCompiler(SQLCompiler):
if
hasattr
(
val
,
'resolve_expression'
):
if
hasattr
(
val
,
'resolve_expression'
):
val
=
val
.
resolve_expression
(
self
.
query
,
allow_joins
=
False
,
for_save
=
True
)
val
=
val
.
resolve_expression
(
self
.
query
,
allow_joins
=
False
,
for_save
=
True
)
if
val
.
contains_aggregate
:
if
val
.
contains_aggregate
:
raise
FieldError
(
"Aggregate functions are not allowed in this query"
)
raise
FieldError
(
'Aggregate functions are not allowed in this query '
'(
%
s=
%
r).'
%
(
field
.
name
,
val
)
)
if
val
.
contains_over_clause
:
if
val
.
contains_over_clause
:
raise
FieldError
(
'Window expressions are not allowed in this query.'
)
raise
FieldError
(
'Window expressions are not allowed in this query '
'(
%
s=
%
r).'
%
(
field
.
name
,
val
)
)
elif
hasattr
(
val
,
'prepare_database_save'
):
elif
hasattr
(
val
,
'prepare_database_save'
):
if
field
.
remote_field
:
if
field
.
remote_field
:
val
=
field
.
get_db_prep_save
(
val
=
field
.
get_db_prep_save
(
...
...
tests/expressions/tests.py
Dosyayı görüntüle @
741ce81a
...
@@ -264,7 +264,8 @@ class BasicExpressionsTests(TestCase):
...
@@ -264,7 +264,8 @@ class BasicExpressionsTests(TestCase):
def
test_object_create_with_aggregate
(
self
):
def
test_object_create_with_aggregate
(
self
):
# Aggregates are not allowed when inserting new data
# Aggregates are not allowed when inserting new data
with
self
.
assertRaisesMessage
(
FieldError
,
'Aggregate functions are not allowed in this query'
):
msg
=
'Aggregate functions are not allowed in this query (num_employees=Max(Value(1))).'
with
self
.
assertRaisesMessage
(
FieldError
,
msg
):
Company
.
objects
.
create
(
Company
.
objects
.
create
(
name
=
'Company'
,
num_employees
=
Max
(
Value
(
1
)),
num_chairs
=
1
,
name
=
'Company'
,
num_employees
=
Max
(
Value
(
1
)),
num_chairs
=
1
,
ceo
=
Employee
.
objects
.
create
(
firstname
=
"Just"
,
lastname
=
"Doit"
,
salary
=
30
),
ceo
=
Employee
.
objects
.
create
(
firstname
=
"Just"
,
lastname
=
"Doit"
,
salary
=
30
),
...
...
tests/expressions_window/tests.py
Dosyayı görüntüle @
741ce81a
...
@@ -670,7 +670,12 @@ class WindowFunctionTests(TestCase):
...
@@ -670,7 +670,12 @@ class WindowFunctionTests(TestCase):
def
test_fail_update
(
self
):
def
test_fail_update
(
self
):
"""Window expressions can't be used in an UPDATE statement."""
"""Window expressions can't be used in an UPDATE statement."""
msg
=
'Window expressions are not allowed in this query'
msg
=
(
'Window expressions are not allowed in this query (salary=<Window: '
'Max(Col(expressions_window_employee, expressions_window.Employee.salary)) '
'OVER (PARTITION BY Col(expressions_window_employee, '
'expressions_window.Employee.department))>).'
)
with
self
.
assertRaisesMessage
(
FieldError
,
msg
):
with
self
.
assertRaisesMessage
(
FieldError
,
msg
):
Employee
.
objects
.
filter
(
department
=
'Management'
)
.
update
(
Employee
.
objects
.
filter
(
department
=
'Management'
)
.
update
(
salary
=
Window
(
expression
=
Max
(
'salary'
),
partition_by
=
'department'
),
salary
=
Window
(
expression
=
Max
(
'salary'
),
partition_by
=
'department'
),
...
@@ -678,7 +683,10 @@ class WindowFunctionTests(TestCase):
...
@@ -678,7 +683,10 @@ class WindowFunctionTests(TestCase):
def
test_fail_insert
(
self
):
def
test_fail_insert
(
self
):
"""Window expressions can't be used in an INSERT statement."""
"""Window expressions can't be used in an INSERT statement."""
msg
=
'Window expressions are not allowed in this query'
msg
=
(
'Window expressions are not allowed in this query (salary=<Window: '
'Sum(Value(10000), order_by=OrderBy(F(pk), descending=False)) OVER ()'
)
with
self
.
assertRaisesMessage
(
FieldError
,
msg
):
with
self
.
assertRaisesMessage
(
FieldError
,
msg
):
Employee
.
objects
.
create
(
Employee
.
objects
.
create
(
name
=
'Jameson'
,
department
=
'Management'
,
hire_date
=
datetime
.
date
(
2007
,
7
,
1
),
name
=
'Jameson'
,
department
=
'Management'
,
hire_date
=
datetime
.
date
(
2007
,
7
,
1
),
...
...
tests/update/tests.py
Dosyayı görüntüle @
741ce81a
...
@@ -165,7 +165,11 @@ class AdvancedTests(TestCase):
...
@@ -165,7 +165,11 @@ class AdvancedTests(TestCase):
self
.
assertEqual
(
qs
.
update
(
another_value
=
F
(
'alias'
)),
3
)
self
.
assertEqual
(
qs
.
update
(
another_value
=
F
(
'alias'
)),
3
)
# Update where aggregation annotation is used in update parameters
# Update where aggregation annotation is used in update parameters
qs
=
DataPoint
.
objects
.
annotate
(
max
=
Max
(
'value'
))
qs
=
DataPoint
.
objects
.
annotate
(
max
=
Max
(
'value'
))
with
self
.
assertRaisesMessage
(
FieldError
,
'Aggregate functions are not allowed in this query'
):
msg
=
(
'Aggregate functions are not allowed in this query '
'(another_value=Max(Col(update_datapoint, update.DataPoint.value))).'
)
with
self
.
assertRaisesMessage
(
FieldError
,
msg
):
qs
.
update
(
another_value
=
F
(
'max'
))
qs
.
update
(
another_value
=
F
(
'max'
))
def
test_update_annotated_multi_table_queryset
(
self
):
def
test_update_annotated_multi_table_queryset
(
self
):
...
@@ -185,5 +189,9 @@ class AdvancedTests(TestCase):
...
@@ -185,5 +189,9 @@ class AdvancedTests(TestCase):
# self.assertEqual(updated, 1)
# self.assertEqual(updated, 1)
# Update where aggregation annotation is used in update parameters
# Update where aggregation annotation is used in update parameters
qs
=
RelatedPoint
.
objects
.
annotate
(
max
=
Max
(
'data__value'
))
qs
=
RelatedPoint
.
objects
.
annotate
(
max
=
Max
(
'data__value'
))
with
self
.
assertRaisesMessage
(
FieldError
,
'Aggregate functions are not allowed in this query'
):
msg
=
(
'Aggregate functions are not allowed in this query '
'(name=Max(Col(update_datapoint, update.DataPoint.value))).'
)
with
self
.
assertRaisesMessage
(
FieldError
,
msg
):
qs
.
update
(
name
=
F
(
'max'
))
qs
.
update
(
name
=
F
(
'max'
))
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