Opened 3 years ago

Closed 3 years ago

#33071 closed Bug (duplicate)

ContentType selects wrong DB in multiple DB setup

Reported by: Taylor H Owned by: nobody
Component: contrib.contenttypes Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Taylor H)

I just introduced multiple DBs in my Django app to split up some of the write/read load. I found that ContentType does not work across multiple DBs with GenericForeignKey. It is hard coded to use the same DB as the source model. Here is the code that has a hard coded .using().

def get_all_objects_for_this_type(self, **kwargs):
        """
        Return all objects of this type for the keyword arguments given.
        """
        return self.model_class()._base_manager.using(self._state.db).filter(**kwargs)

https://github.com/django/django/blame/main/django/contrib/contenttypes/models.py#L181

Is there are reason for hard coding using() here instead of using the DB router like other places in the code? If we could just removing the using everything just works

Change History (2)

comment:1 by Taylor H, 3 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 3 years ago

Resolution: duplicate
Status: newclosed
Type: UncategorizedBug

I'm pretty sure it's a duplicate of #15610 or #16281.

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