#34321: Unexpected query result after call QuerySet.only() to ForeignKey() with
'self' reference
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
Mahardhika Praja Taruna Negara |
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords: queryset
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Unexpected query result after calling `QuerySet.only('ref__field')` to
`ForeignKey('self')`
{{{#!python
class MyModel(models.Model):
f1 = models.IntegerField()
f2 = models.IntegerField()
f3 = models.IntegerField()
ref = models.ForeignKey("self", on_delete=models.CASCADE)
print(str(MyModel.objects.select_related('ref').only('ref__f1').query))
}}}
Output
{{{
'SELECT "mymodel"."id", "mymodel"."f1", "mymodel"."ref_id", T2."id",
T2."f1", T2."ref_id" FROM "mymodel" INNER JOIN "mymodel" T2 ON
("mymodel"."ref_id" = T2."id")'
}}}
Fields `"mymodel"."f2"` and `"mymodel"."f3"` are excluded from column
selection
--
Ticket URL: <https://code.djangoproject.com/ticket/34321>
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/010701863068dc42-0e55128c-3382-493e-97da-fff6ed039ea4-000000%40eu-central-1.amazonses.com.