Opened 13 years ago
Closed 13 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 by , 13 years ago
comment:2 by , 13 years ago
Cc: | added |
---|---|
Needs tests: | set |
Severity: | Normal → Release blocker |
Version: | SVN → 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 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 13 years ago
@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.
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?