Opened 5 years ago

Closed 4 years ago

#17696 closed Bug (fixed)

Queryset prefetch_related() ignores using()

Reported by: simon29 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


Example --


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 akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 simon29

  • Cc simon@… added
  • Needs tests set
  • Severity changed from Normal to Release blocker
  • Version changed from SVN to 1.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 lrekucki

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 5 years ago by lukeplant

@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 4 years ago by lukeplant

  • Resolution set to fixed
  • Status changed from new to closed

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