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
adab280c
Kaydet (Commit)
adab280c
authored
Tem 14, 2017
tarafından
Florian Apolloner
Kaydeden (comit)
Tim Graham
Tem 15, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28399 -- Fixed QuerySet.count() for union(), difference(), and intersection() queries.
üst
9290f15b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
11 deletions
+39
-11
compiler.py
django/db/models/sql/compiler.py
+1
-1
query.py
django/db/models/sql/query.py
+5
-5
querysets.txt
docs/ref/models/querysets.txt
+9
-5
1.11.4.txt
docs/releases/1.11.4.txt
+3
-0
test_qs_combinators.py
tests/queries/test_qs_combinators.py
+21
-0
No files found.
django/db/models/sql/compiler.py
Dosyayı görüntüle @
adab280c
...
...
@@ -410,7 +410,7 @@ class SQLCompiler:
continue
raise
if
not
parts
:
r
eturn
[],
[]
r
aise
EmptyResultSet
combinator_sql
=
self
.
connection
.
ops
.
set_operators
[
combinator
]
if
all
and
combinator
==
'union'
:
combinator_sql
+=
' ALL'
...
...
django/db/models/sql/query.py
Dosyayı görüntüle @
adab280c
...
...
@@ -411,12 +411,12 @@ class Query:
# aren't smart enough to remove the existing annotations from the
# query, so those would force us to use GROUP BY.
#
# If the query has limit or distinct,
then those operations must be
#
done in a subquery so that we are aggregating on the limit and/or
#
distinct results instead of applying the distinct and limit after the
# aggregation.
# If the query has limit or distinct,
or uses set operations, then
#
those operations must be done in a subquery so that the query
#
aggregates on the limit and/or distinct results instead of applying
#
the distinct and limit after the
aggregation.
if
(
isinstance
(
self
.
group_by
,
tuple
)
or
has_limit
or
has_existing_annotations
or
self
.
distinct
):
self
.
distinct
or
self
.
combinator
):
from
django.db.models.sql.subqueries
import
AggregateQuery
outer_query
=
AggregateQuery
(
self
.
model
)
inner_query
=
self
.
clone
()
...
...
docs/ref/models/querysets.txt
Dosyayı görüntüle @
adab280c
...
...
@@ -821,11 +821,15 @@ of other models. Passing different models works as long as the ``SELECT`` list
is the same in all ``QuerySet``\s (at least the types, the names don't matter
as long as the types in the same order).
In addition, only ``LIMIT``, ``OFFSET``, and ``ORDER BY`` (i.e. slicing and
:meth:`order_by`) are allowed on the resulting ``QuerySet``. Further, databases
place restrictions on what operations are allowed in the combined queries. For
example, most databases don't allow ``LIMIT`` or ``OFFSET`` in the combined
queries.
In addition, only ``LIMIT``, ``OFFSET``, ``COUNT(*)``, and ``ORDER BY`` (i.e.
slicing, :meth:`count`, and :meth:`order_by`) are allowed on the resulting
``QuerySet``. Further, databases place restrictions on what operations are
allowed in the combined queries. For example, most databases don't allow
``LIMIT`` or ``OFFSET`` in the combined queries.
.. versionchanged:: 1.11.4
``COUNT(*)`` support was added.
``intersection()``
~~~~~~~~~~~~~~~~~~
...
...
docs/releases/1.11.4.txt
Dosyayı görüntüle @
adab280c
...
...
@@ -25,3 +25,6 @@ Bugfixes
* Corrected ``Field.has_changed()`` to return ``False`` for disabled form
fields: ``BooleanField``, ``MultipleChoiceField``, ``MultiValueField``,
``FileField``, ``ModelChoiceField``, and ``ModelMultipleChoiceField``.
* Fixed ``QuerySet.count()`` for ``union()``, ``difference()``, and
``intersection()`` queries. (:ticket:`28399`).
tests/queries/test_qs_combinators.py
Dosyayı görüntüle @
adab280c
...
...
@@ -89,6 +89,27 @@ class QuerySetSetOperationTests(TestCase):
qs2
=
Number
.
objects
.
filter
(
num__gte
=
2
,
num__lte
=
3
)
self
.
assertNumbersEqual
(
qs1
.
union
(
qs2
)
.
order_by
(
'-num'
),
[
3
,
2
,
1
,
0
])
def
test_count_union
(
self
):
qs1
=
Number
.
objects
.
filter
(
num__lte
=
1
)
.
values
(
'num'
)
qs2
=
Number
.
objects
.
filter
(
num__gte
=
2
,
num__lte
=
3
)
.
values
(
'num'
)
self
.
assertEqual
(
qs1
.
union
(
qs2
)
.
count
(),
4
)
def
test_count_union_empty_result
(
self
):
qs
=
Number
.
objects
.
filter
(
pk__in
=
[])
self
.
assertEqual
(
qs
.
union
(
qs
)
.
count
(),
0
)
@skipUnlessDBFeature
(
'supports_select_difference'
)
def
test_count_difference
(
self
):
qs1
=
Number
.
objects
.
filter
(
num__lt
=
10
)
qs2
=
Number
.
objects
.
filter
(
num__lt
=
9
)
self
.
assertEqual
(
qs1
.
difference
(
qs2
)
.
count
(),
1
)
@skipUnlessDBFeature
(
'supports_select_intersection'
)
def
test_count_intersection
(
self
):
qs1
=
Number
.
objects
.
filter
(
num__gte
=
5
)
qs2
=
Number
.
objects
.
filter
(
num__lte
=
5
)
self
.
assertEqual
(
qs1
.
intersection
(
qs2
)
.
count
(),
1
)
@skipUnlessDBFeature
(
'supports_slicing_ordering_in_compound'
)
def
test_ordering_subqueries
(
self
):
qs1
=
Number
.
objects
.
order_by
(
'num'
)[:
2
]
...
...
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