#33608: Wrong sql generation for FK with db_constraint=False causing results to incorrectly get dropped from a queryset -------------------------------------+------------------------------------- Reporter: Mathieu | Owner: nobody Hinderyckx | Type: Bug | Status: new Component: Database | Version: 4.0 layer (models, ORM) | Severity: Normal | Keywords: Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- When using a FK which has db_constraint=False, the sql generated when using the combination of a filter() and select_related() are wrong, causing results which should be included in a queryset to not be.
The problem occurs when the remote object does not exist in the table where the FK points to. In some cases the ORM will generate an `INNER JOIN` statement instead of a `LEFT OUTER JOIN` causing a row to be wrongly omitted. I have made a POC setup for this behaviour on https://github.com/mhindery/django_fk_issue, with testcases containing some working lookups, and one specific method that demonstrate the behaviour. I've included in comments in the tests the query which gets generated, showing the problematic join. -- Ticket URL: <https://code.djangoproject.com/ticket/33608> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107017fda8ae38b-b3c5fa4b-22d2-45cf-bdac-0424443ede27-000000%40eu-central-1.amazonses.com.