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
74261bc5
Kaydet (Commit)
74261bc5
authored
May 29, 2015
tarafından
Gagaro
Kaydeden (comit)
Tim Graham
Haz 18, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24873 -- Prevented nested Prefetch objects from being overwritten.
üst
06747ee7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletion
+17
-1
query.py
django/db/models/query.py
+6
-1
tests.py
tests/prefetch_related/tests.py
+11
-0
No files found.
django/db/models/query.py
Dosyayı görüntüle @
74261bc5
...
@@ -1538,7 +1538,12 @@ def prefetch_one_level(instances, prefetcher, lookup, level):
...
@@ -1538,7 +1538,12 @@ def prefetch_one_level(instances, prefetcher, lookup, level):
# contains some prefetch_related lookups. We don't want to trigger the
# contains some prefetch_related lookups. We don't want to trigger the
# prefetch_related functionality by evaluating the query. Rather, we need
# prefetch_related functionality by evaluating the query. Rather, we need
# to merge in the prefetch_related lookups.
# to merge in the prefetch_related lookups.
additional_lookups
=
getattr
(
rel_qs
,
'_prefetch_related_lookups'
,
[])
# Copy the lookups in case it is a Prefetch object which could be reused
# later (happens in nested prefetch_related).
additional_lookups
=
[
copy
.
copy
(
additional_lookup
)
for
additional_lookup
in
getattr
(
rel_qs
,
'_prefetch_related_lookups'
,
[])
]
if
additional_lookups
:
if
additional_lookups
:
# Don't need to clone because the manager should have given us a fresh
# Don't need to clone because the manager should have given us a fresh
# instance, so we access an internal instead of using public interface
# instance, so we access an internal instead of using public interface
...
...
tests/prefetch_related/tests.py
Dosyayı görüntüle @
74261bc5
...
@@ -626,6 +626,17 @@ class CustomPrefetchTests(TestCase):
...
@@ -626,6 +626,17 @@ class CustomPrefetchTests(TestCase):
room
=
Room
.
objects
.
filter
(
main_room_of__isnull
=
False
)
.
prefetch_related
(
Prefetch
(
'main_room_of'
,
queryset
=
houses
.
filter
(
address
=
'DoesNotExist'
),
to_attr
=
'main_room_of_attr'
))
.
first
()
room
=
Room
.
objects
.
filter
(
main_room_of__isnull
=
False
)
.
prefetch_related
(
Prefetch
(
'main_room_of'
,
queryset
=
houses
.
filter
(
address
=
'DoesNotExist'
),
to_attr
=
'main_room_of_attr'
))
.
first
()
self
.
assertIsNone
(
room
.
main_room_of_attr
)
self
.
assertIsNone
(
room
.
main_room_of_attr
)
def
test_nested_prefetch_related_are_not_overwritten
(
self
):
# Regression test for #24873
houses_2
=
House
.
objects
.
prefetch_related
(
Prefetch
(
'rooms'
))
persons
=
Person
.
objects
.
prefetch_related
(
Prefetch
(
'houses'
,
queryset
=
houses_2
))
houses
=
House
.
objects
.
prefetch_related
(
Prefetch
(
'occupants'
,
queryset
=
persons
))
list
(
houses
)
# queryset must be evaluated once to reproduce the bug.
self
.
assertEqual
(
houses
.
all
()[
0
]
.
occupants
.
all
()[
0
]
.
houses
.
all
()[
1
]
.
rooms
.
all
()[
0
],
self
.
room2_1
)
class
DefaultManagerTests
(
TestCase
):
class
DefaultManagerTests
(
TestCase
):
...
...
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