Code

Opened 3 years ago

Closed 3 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?

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.