Opened 3 years ago
Last modified 3 years ago
#33501 closed Bug
order_with_respect_to uses incorrect database alias — at Initial Version
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. :)