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
6104875a
Kaydet (Commit)
6104875a
authored
May 27, 2018
tarafından
Paulo
Kaydeden (comit)
Tim Graham
May 28, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29230 -- Fixed nested prefetches that clash with descriptors.
üst
e0ff88be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletion
+14
-1
query.py
django/db/models/query.py
+1
-1
tests.py
tests/prefetch_related/tests.py
+13
-0
No files found.
django/db/models/query.py
Dosyayı görüntüle @
6104875a
...
...
@@ -1568,7 +1568,7 @@ def prefetch_related_objects(model_instances, *related_lookups):
# same relationships to stop infinite recursion. So, if we
# are already on an automatically added lookup, don't add
# the new lookups from relationships we've seen already.
if
not
(
lookup
in
auto_lookups
and
descriptor
in
followed_descriptors
):
if
not
(
prefetch_to
in
done_queries
and
lookup
in
auto_lookups
and
descriptor
in
followed_descriptors
):
done_queries
[
prefetch_to
]
=
obj_list
new_lookups
=
normalize_prefetch_lookups
(
reversed
(
additional_lookups
),
prefetch_to
)
auto_lookups
.
update
(
new_lookups
)
...
...
tests/prefetch_related/tests.py
Dosyayı görüntüle @
6104875a
...
...
@@ -772,6 +772,19 @@ class CustomPrefetchTests(TestCase):
self
.
room2_1
)
def
test_nested_prefetch_related_with_duplicate_prefetcher
(
self
):
"""
Nested prefetches whose name clashes with descriptor names
(Person.houses here) are allowed.
"""
occupants
=
Person
.
objects
.
prefetch_related
(
Prefetch
(
'houses'
,
to_attr
=
'some_attr_name'
),
Prefetch
(
'houses'
,
queryset
=
House
.
objects
.
prefetch_related
(
'main_room'
)),
)
houses
=
House
.
objects
.
prefetch_related
(
Prefetch
(
'occupants'
,
queryset
=
occupants
))
with
self
.
assertNumQueries
(
5
):
self
.
traverse_qs
(
list
(
houses
),
[[
'occupants'
,
'houses'
,
'main_room'
]])
def
test_values_queryset
(
self
):
with
self
.
assertRaisesMessage
(
ValueError
,
'Prefetch querysets cannot use values().'
):
Prefetch
(
'houses'
,
House
.
objects
.
values
(
'pk'
))
...
...
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