Changes between Initial Version and Version 2 of Ticket #33766


Ignore:
Timestamp:
Jun 3, 2022, 7:42:53 PM (2 years ago)
Author:
Daniel Schaffer
Comment:

Sure, I've updated the ticket with a link to a repro repo

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33766 – Description

    initial v2  
    22
    33{{{
    4 Jobs.objects.annotate(
    5     worker_preference=FilteredRelation(
    6         relation_name="company__workerpreference",
    7         condition=Q(
    8             company__workerpreference__worker=Coalesce(F("worker"), F("substitute__worker")),
    9             company__workerpreference__company=F("company"),
    10         )
    11     )
     4            job_worker_preference=FilteredRelation(
     5                relation_name="company__worker_preferences",
     6                condition=Q(
     7                    company__worker_preferences__worker=Coalesce(F("worker"), F("worker_substitutions__worker")),
     8                    company__worker_preferences__company=F("company"),
     9                )
     10            ),
     11            is_allowed=Case(When(job_worker_preference__allow_assignments=True, then=1), default=0, output_field=BooleanField())
    1212}}}
    1313
     
    1515
    1616{{{
    17 Jobs.objects.annotate(
    18     actual_worker=Coalesce(F("worker"), F("substitute__worker")),
    19     worker_preference=FilteredRelation(
    20         relation_name="company__workerpreference",
    21         condition=Q(
    22             company__workerpreference__worker=F("actual_worker"),
    23             company__workerpreference__company=F("company"),
    24         )
    25     )
     17            actual_worker=Coalesce(F("worker"), F("worker_substitutions__worker")),
     18            job_worker_preference=FilteredRelation(
     19                relation_name="company__worker_preferences",
     20                condition=Q(
     21                    company__worker_preferences__worker=F("actual_worker"),
     22                    company__worker_preferences__company=F("company"),
     23                )
     24            ),
     25            is_allowed=Case(When(job_worker_preference__allow_assignments=True, then=1), default=0, output_field=BooleanField())
    2626}}}
    2727
    2828However, I suspect there may be an underlying issue with how JOINs are detected and added to a query when there are nested field references like this.
     29
     30I've reproduced the issue in this repro: https://github.com/DanielSchaffer/django_filtered_relation_coalesce_repro.
     31
     32`django_filtered_relation_coalesce_repro/test/test_job_manager.py`  contains a failing test that reproduces the issue, and a passing test that demonstrates the workaround.
     33
Back to Top