[Django] #33071: ContentType selects wrong DB in multiple DB setup

6 views
Skip to first unread message

Django

unread,
Aug 30, 2021, 10:30:44 AM8/30/21
to django-...@googlegroups.com
#33071: ContentType selects wrong DB in multiple DB setup
------------------------------------------------+------------------------
Reporter: Taylor H | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.contenttypes | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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/parent 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

--
Ticket URL: <https://code.djangoproject.com/ticket/33071>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 30, 2021, 10:31:31 AM8/30/21
to django-...@googlegroups.com
#33071: ContentType selects wrong DB in multiple DB setup
-------------------------------------+-------------------------------------

Reporter: Taylor H | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 3.2
contrib.contenttypes |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Taylor H:

Old description:

> 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/parent 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

New description:

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33071#comment:1>

Django

unread,
Aug 30, 2021, 1:36:17 PM8/30/21
to django-...@googlegroups.com
#33071: ContentType selects wrong DB in multiple DB setup
-------------------------------------+-------------------------------------

Reporter: Taylor H | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 3.2
contrib.contenttypes |
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* type: Uncategorized => Bug
* resolution: => duplicate


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/33071#comment:2>

Reply all
Reply to author
Forward
0 new messages