1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #29810 -- Fixed crash of select_related() on FilteredRelation with empty result.

This commit is contained in:
can
2019-04-23 13:56:05 +03:00
committed by Mariusz Felisiak
parent 6fd9c9daa6
commit c00b4dbda2
2 changed files with 9 additions and 1 deletions

View File

@@ -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)