Opened 3 years ago

Last modified 3 years ago

#33501 closed Bug

order_with_respect_to uses incorrect database alias — at Version 1

Reported by: Damian Posener Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Simon Charette Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Damian Posener)

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. :)

Change History (1)

comment:1 by Damian Posener, 3 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top