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
c002a0d3
Kaydet (Commit)
c002a0d3
authored
Agu 05, 2016
tarafından
Johannes Dollinger
Kaydeden (comit)
Tim Graham
Agu 08, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26517 -- Fixed ExpressionWrapper with empty queryset.
üst
1410616e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
2 deletions
+20
-2
compiler.py
django/db/models/sql/compiler.py
+6
-1
tests.py
tests/annotations/tests.py
+14
-1
No files found.
django/db/models/sql/compiler.py
Dosyayı görüntüle @
c002a0d3
...
...
@@ -223,7 +223,12 @@ class SQLCompiler(object):
ret
=
[]
for
col
,
alias
in
select
:
ret
.
append
((
col
,
self
.
compile
(
col
,
select_format
=
True
),
alias
))
try
:
sql
,
params
=
self
.
compile
(
col
,
select_format
=
True
)
except
EmptyResultSet
:
# Select a predicate that's always False.
sql
,
params
=
'0'
,
()
ret
.
append
((
col
,
(
sql
,
params
),
alias
))
return
ret
,
klass_info
,
annotations
def
get_order_by
(
self
):
...
...
tests/annotations/tests.py
Dosyayı görüntüle @
c002a0d3
...
...
@@ -6,7 +6,7 @@ from decimal import Decimal
from
django.core.exceptions
import
FieldDoesNotExist
,
FieldError
from
django.db.models
import
(
BooleanField
,
CharField
,
Count
,
DateTimeField
,
ExpressionWrapper
,
F
,
Func
,
IntegerField
,
Sum
,
Value
,
IntegerField
,
Q
,
Sum
,
Value
,
)
from
django.db.models.functions
import
Lower
from
django.test
import
TestCase
,
skipUnlessDBFeature
...
...
@@ -148,6 +148,19 @@ class NonAggregateAnnotationTestCase(TestCase):
combined
=
int
(
test
.
pages
+
test
.
rating
)
self
.
assertEqual
(
b
.
combined
,
combined
)
def
test_empty_expression_annotation
(
self
):
books
=
Book
.
objects
.
annotate
(
selected
=
ExpressionWrapper
(
Q
(
pk__in
=
[]),
output_field
=
BooleanField
())
)
self
.
assertEqual
(
len
(
books
),
Book
.
objects
.
count
())
self
.
assertTrue
(
all
(
not
book
.
selected
for
book
in
books
))
books
=
Book
.
objects
.
annotate
(
selected
=
ExpressionWrapper
(
Q
(
pk__in
=
Book
.
objects
.
none
()),
output_field
=
BooleanField
())
)
self
.
assertEqual
(
len
(
books
),
Book
.
objects
.
count
())
self
.
assertTrue
(
all
(
not
book
.
selected
for
book
in
books
))
def
test_annotate_with_aggregation
(
self
):
books
=
Book
.
objects
.
annotate
(
is_book
=
Value
(
1
,
output_field
=
IntegerField
()),
...
...
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