#34620: Serialization of m2m relation fails with custom manager using
select_related
-------------------------------------+-------------------------------------
     Reporter:  Martin Svoboda       |                    Owner:  Mariusz
                                     |  Felisiak
         Type:  Bug                  |                   Status:  closed
    Component:  Core                 |                  Version:  4.2
  (Serialization)                    |
     Severity:  Release blocker      |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Juan Alvarez):

 Mariusz,

 I think you want `select_related(None)` instead of `select_related()`,
 since the latter will try to join against all non-nullable FKs. The reason
 your tests were passing is that the test model's FK has `null=True`.

 Per the [[https://docs.djangoproject.com/en/4.2/ref/models/querysets
 /#select-related|docs]]:

 > [...] it is possible to call select_related() with no arguments. **This
 will follow all non-null foreign keys it can find** - nullable foreign
 keys must be specified. This is not recommended in most cases as it is
 likely to make the underlying query more complex, and return more data,
 than is actually needed. **If you need to clear the list of related fields
 added by past calls of select_related on a QuerySet, you can pass None as
 a parameter**.

 I have submitted a [[https://code.djangoproject.com/ticket/34779|ticket]]
 and a [[https://github.com/django/django/pull/17164|PR]]. Do you mind help
 me review them?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34620#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/01070189ffc791d5-de1710de-f121-45b1-9063-e5e480ab87c3-000000%40eu-central-1.amazonses.com.

Reply via email to