#34589: exclude does not support nested ForeignKey relationship
-------------------------------------+-------------------------------------
Reporter: ftamy9 | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: 4.1 | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by ftamy9:
Old description:
> I need to find trips that are not
> `trip__method__title=ShippingChoice.ORGANIZATION`
> my code is like this:
>
> {{{
> working_shipments = Shipment.objects.exclude(
> state__in=[
> ShipmentStateChoices.CANCELLED,
> ShipmentStateChoices.DELIVERED
> ],
> trip__method__title=ShippingChoice.ORGANIZATION
> ).filter(
> updated_at__lt=time_threshold,
> )
> }}}
>
> I forced to use a big list on filter instead to use the exclude. my code
> is like this:
>
> {{{
> working_shipments = Shipment.objects.exclude(
> state__in=[
> ShipmentStateChoices.CANCELLED,
> ShipmentStateChoices.DELIVERED
> ]
> ).filter(
> updated_at__lt=time_threshold,
> trip__method__title__in=(ShippingChoice.ALO,
> ShippingChoice.SNAP, ShippingChoice.MIAREH)
> )
>
> }}}
New description:
There is a problem on exclude. you can not use nested ForeignKey. I tested
on 4.2.1 and 4.1.
for example if you need to find trips that are not
`trip__method__title=ShippingChoice.ORGANIZATION`
Here is the code:
{{{
working_shipments = Shipment.objects.exclude(
state__in=[
ShipmentStateChoices.CANCELLED,
ShipmentStateChoices.DELIVERED
],
trip__method__title=ShippingChoice.ORGANIZATION
).filter(
updated_at__lt=time_threshold,
)
}}}
So you are forced to use a big list on filter instead to use the exclude.
like this:
{{{
working_shipments = Shipment.objects.exclude(
state__in=[
ShipmentStateChoices.CANCELLED,
ShipmentStateChoices.DELIVERED
]
).filter(
updated_at__lt=time_threshold,
trip__method__title__in=(ShippingChoice.ALO, ShippingChoice.SNAP,
ShippingChoice.MIAREH)
)
}}}
the objects.exclude bug need to fix
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:8>
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/0107018843c80b0f-89032291-4a60-4cd3-9899-d1143a47e5ce-000000%40eu-central-1.amazonses.com.