#28939: QuerySet used by prefetch_related() does not use expected connection.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch, | Triage Stage: Accepted
prefetch_related, using, |
connection |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* stage: Unreviewed => Accepted
Comment:
I think 1. would make the most sense here unfortunately I'm afraid this
might break backward compatibility with regards to database router.
For example, given the following scenario
{{{#!python
class Foo(models.Model):
pass
class Bar(models.Model):
foo = models.ForeignKey(Foo, related_name='bars')
class Router(object):
def db_for_read(self, model):
if model is Bar:
return 'other'
return 'default'
}}}
It would change the behaviour of
`Foo.objects.using('default').prefetch_related('bars')` because `using()`
has usually precedence over the routers suggestion. We could special case
prefetches to only default to the base queryset's `using` if no router
provide a `db_for_read` suggestion but that would be counter intuitive IMO
and add even more complexity to the read database alias selection logic.
So, I think that 1. is favourable but would require a deprecation cycle
for the case where both a base query alias is forced though `using` and
that `db_for_read` suggests a database. In the mean time I think that 3.
is easier to implement and could be useful even in a future where 1. would
get fixed.
--
Ticket URL: <https://code.djangoproject.com/ticket/28939#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.4142e848940c8bd7938f7707911a28f3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.