Opened 13 years ago

Closed 13 years ago

#16240 closed Bug (invalid)

Querying models with foreign keys in multidb doesn't use right DB

Reported by: aviv.by@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords: multidb foreignkey
Cc: aviv.by@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've got a setup with multidb and a router that splits traffic between two connections by tables.
The problem I'm seeing is that, say I've got a Book model that has a foreign key to an Author model, and each one is managed in a different DB connection (as is decided by the router I created), the following query works correctly:

Book.objects.filter(author__id__gt=x)

That works as expected since the IDs of author are also present in the Book table, but every other attribute I attempt to access is being fetched from Book's DB instead of Author's DB, which causes broken behavior. For example, this will fetch both objects from the same DB:

Book.objects.filter(author__first_name='John')

Is there some kind of workaround to get this to work as it should?

Change History (1)

Note: See TracTickets for help on using tickets.
Back to Top