Opened 4 years ago

Closed 4 years ago

#22596 closed New feature (duplicate)

revert select_related

Reported by: qcxhome@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In some complicated situation, a QuerySet is passed through several methods to construct the final QuerySet. In this case, it's useful for developers to revert previous select_related due to that is not necessary for the final query. Fox example, a QuerySet like following is passed to another method,

# qs is constructed a little far from invocation to final_query
qs = MyModel.objects.filter(...).select_related('author', 'priority')

result = final_query(qs)

only MyModel.summary field is required from the final query result. Definition of final_query would be

def final_query(qs):
    return qs.only('summary')

but, the select_related is also applied to the final QuerySet. With the ability this ticket is requesting, developers are able to revert all unnecessary related fields. It's much convenient.

Change History (1)

comment:1 Changed 4 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

This has been added in 1.7, see #16856.

Note: See TracTickets for help on using tickets.
Back to Top