#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:

> 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

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 fixed

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34589#comment:9>
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/0107018843c846c0-4eb8d219-27cb-4d95-becf-0fccb3031769-000000%40eu-central-1.amazonses.com.

Reply via email to