#36954: Filtering an ManyToManyField causes the `.values` call to be filtered
-------------------------------------+-------------------------------------
Reporter: Ryan "RB" Barnes | Owner: Mahi
| Singhal
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Ryan "RB" Barnes):
Hi Simon,
Thanks for the reply.
As stated at the end of my ticket I am aware of the possible workarounds
but the requirement for a workaround is my problem with the SQL being
generated.
My issue with the following querysets is that they produce different
results because of the generated SQL and that is unexpected.
{{{
Appointment.objects.filter(id=appointment.id).values_list('technicians',
flat=True)
# [1, 2]
Appointment.objects.filter(id=appointment.id,
technicians__in=[tech_1]).values_list('technicians', flat=True)
# [1]
}}}
Accessing technicians from a filtered queryset produces different results
{{{
qs = Appointment.objects.filter(id=appointment.id,
technicians__in=[tech_1])
qs.values_list('technicians', flat=True)
# [1]
qs.get().technicians.all()
# [1, 2]
}}}
The engineers I've talked to were not aware of this interaction as it
feels unintuitive.
Either way I will keep this in mind as another thing that the ORM
abstraction does not address.
Thank you for your time on this matter.
--
Ticket URL: <https://code.djangoproject.com/ticket/36954#comment:3>
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 visit
https://groups.google.com/d/msgid/django-updates/0107019c9c58df55-7d0b58a1-caf2-4801-9b1a-d5d0b9c1ccd1-000000%40eu-central-1.amazonses.com.