#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
     Reporter:  zhu                  |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by zhu):

 Replying to [comment:6 Mariusz Felisiak]:
 > Thanks! Would you like to prepare a patch?
 {{{
 diff --git a/django/db/models/sql/compiler.py
 b/django/db/models/sql/compiler.py
 index 2b66ab12b4..831ef79269 100644
 --- a/django/db/models/sql/compiler.py
 +++ b/django/db/models/sql/compiler.py
 @@ -1261,7 +1261,7 @@ class SQLCompiler:
                  )
                  get_related_klass_infos(klass_info, next_klass_infos)

 -            def local_setter(obj, from_obj):
 +            def local_setter(f, obj, from_obj):
                  # Set a reverse fk object when relation is non-empty.
                  if from_obj:
                      f.remote_field.set_cached_value(from_obj, obj)
 @@ -1287,7 +1287,7 @@ class SQLCompiler:
                          "model": model,
                          "field": f,
                          "reverse": True,
 -                        "local_setter": local_setter,
 +                        "local_setter": partial(local_setter, f),
                          "remote_setter": partial(remote_setter, name),
                          "from_parent": from_parent,
                      }
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701853eb05a9a-78180e3f-901f-421c-8e6a-85e7d7d2e850-000000%40eu-central-1.amazonses.com.

Reply via email to