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
c00b4dbd
Kaydet (Commit)
c00b4dbd
authored
Nis 23, 2019
tarafından
can
Kaydeden (comit)
Mariusz Felisiak
Nis 23, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29810 -- Fixed crash of select_related() on FilteredRelation with empty result.
üst
6fd9c9da
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
1 deletion
+9
-1
compiler.py
django/db/models/sql/compiler.py
+3
-1
tests.py
tests/filtered_relation/tests.py
+6
-0
No files found.
django/db/models/sql/compiler.py
Dosyayı görüntüle @
c00b4dbd
...
...
@@ -892,7 +892,9 @@ class SQLCompiler:
from_parent
=
issubclass
(
model
,
opts
.
model
)
and
model
is
not
opts
.
model
def
local_setter
(
obj
,
from_obj
):
f
.
remote_field
.
set_cached_value
(
from_obj
,
obj
)
# Set a reverse fk object when relation is non-empty.
if
from_obj
:
f
.
remote_field
.
set_cached_value
(
from_obj
,
obj
)
def
remote_setter
(
obj
,
from_obj
):
setattr
(
from_obj
,
name
,
obj
)
...
...
tests/filtered_relation/tests.py
Dosyayı görüntüle @
c00b4dbd
...
...
@@ -50,6 +50,12 @@ class FilteredRelationTests(TestCase):
(
self
.
author2
,
self
.
book3
,
self
.
editor_b
,
self
.
author2
),
],
lambda
x
:
(
x
,
x
.
book_join
,
x
.
book_join
.
editor
,
x
.
book_join
.
author
))
def
test_select_related_with_empty_relation
(
self
):
qs
=
Author
.
objects
.
annotate
(
book_join
=
FilteredRelation
(
'book'
,
condition
=
Q
(
pk
=-
1
)),
)
.
select_related
(
'book_join'
)
.
order_by
(
'pk'
)
self
.
assertSequenceEqual
(
qs
,
[
self
.
author1
,
self
.
author2
])
def
test_select_related_foreign_key
(
self
):
qs
=
Book
.
objects
.
annotate
(
author_join
=
FilteredRelation
(
'author'
),
...
...
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