Opened 5 years ago

Closed 5 years ago

#17696 closed Bug (fixed)

Queryset prefetch_related() ignores using()

Reported by: Simon Litchfield Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4-alpha-1
Severity: Release blocker Keywords: prefetch_related
Cc: simon@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Example --

MyModel.objects.using('mydatabase').prefetch_related('field').all()

It appears the using() part is ignored, the 'default' database is used instead (r17428).

Happy to submit a patch if it'll be used.....

Change History (5)

comment:1 Changed 5 years ago by Anssi Kääriäinen

There is a small problem with altering the behavior. Currently, what prefetch_related does is it fetches the related queryset. Now, if that related queryset has .using() defined, then it must not use the .using() of the outer queryset.

Maybe the related qs should use the .using() of the outer queryset only if there is no .using() defined for the related queryset?

comment:2 Changed 5 years ago by Simon Litchfield

Cc: simon@… added
Needs tests: set
Severity: NormalRelease blocker
Version: SVN1.4-alpha-1

Agreed, we'll let the related (inner) queryset's using() take precedence, if defined.

I've upped this to a 1.4 release blocker, since it's a bug on functionality already slated for inclusion in 1.4.

Once I get a blessing from above I'll code it up :-)

comment:3 Changed 5 years ago by Łukasz Rekucki

Triage Stage: UnreviewedAccepted

comment:4 Changed 5 years ago by Luke Plant

@simon29 - please do submit a patch along the lines agreed. Even better if it has tests.

I'll take responsibility for review and committing. If you won't be able to do this soon let me know and I'll write the patch.

Many thanks.

comment:5 Changed 5 years ago by Luke Plant

Resolution: fixed
Status: newclosed

In [17605]:

Fixed #17696 - Queryset prefetch_related() ignores using()

Thanks to simon29 for the report.

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