#33501: order_with_respect_to uses incorrect database alias
-------------------------------------+-------------------------------------
Reporter: Damian Posener | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Damian Posener:
Old description:
> When calling set_RELATED_order on a model that uses
> order_with_respect_to, if a DB router exists that routes that model to a
> non-default database, the routing is ignored, causing a datbase error to
> occur.
>
> I've tracked this down to the method_set_order function here:
> https://github.com/django/django/blob/3.2.12/django/db/models/base.py#L2117
>
> This function updates `using=None` to `using=DEFAULT_DB_ALIAS`, which
> then overrides any database routing set up on the model manager. It
> should just pass through `using=None` so that the manager can deal with
> determining the correct connection to use.
>
> I believe this got inadvertently broken in #30106 - previously the
> `using` parameter was actually being ignored, but when that got fixed it
> caused this new error. :)
New description:
PR: https://github.com/django/django/pull/15409
When calling set_RELATED_order on a model that uses order_with_respect_to,
if a DB router exists that routes that model to a non-default database,
the routing is ignored, causing a datbase error to occur.
I've tracked this down to the method_set_order function here:
https://github.com/django/django/blob/3.2.12/django/db/models/base.py#L2117
This function updates `using=None` to `using=DEFAULT_DB_ALIAS`, which then
overrides any database routing set up on the model manager. It should just
pass through `using=None` so that the manager can deal with determining
the correct connection to use.
I believe this got inadvertently broken in #30106 - previously the `using`
parameter was actually being ignored, but when that got fixed it caused
this new error. :)
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33501#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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.34e5eb32f645ce213a45a77c5bda419f%40djangoproject.com.