[Django] #27164: Multiple problems with multiple database docs for 1.8 and possibly other versions

ā§§ā§ĢāĻŸāĻŋ āĻ­āĻŋāĻ‰
āĻĒā§āĻ°āĻĨāĻŽ āĻ…āĻĒāĻ āĻŋāĻ¤ āĻŽā§‡āĻ¸ā§‡āĻœāĻŸāĻŋāĻ¤ā§‡ āĻšāĻ˛ā§‡ āĻ†āĻ¸ā§āĻ¨

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§§ āĻ¸ā§‡āĻĒ, ā§¨ā§Ļā§§ā§Ŧ, ā§§ā§¨:ā§§ā§Ē:ā§¨ā§Ŧ AMā§§/ā§¯/ā§§ā§Ŧ
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Multiple problems with multiple database docs for 1.8 and possibly other
versions
----------------------------------------------+----------------------------
Reporter: michaelcoconnor | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords: multiple
| databases docs
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------------------+----------------------------
I am running (1, 8, 7, 'final', 0); this ticket pertains specifically to
https://docs.djangoproject.com/en/1.8/topics/db/multi-db/ and to the code
snippets in it.

First, in the discussion of Database Routers and in the code for the
router AuthRouter(), the declaration of the method controlling migrations
is allow_migrate(db, app_label, model_name=None, *hints), which is stated
to be new in 1.8, the 1.7 version having been deprecated. However, in
reality in (1, 8, 7, 'final', 0) only the 1.7 version of this method
works.

Secondly, the AuthRouter() code is designed to only permit apps with
app_label =='auth' to be migrated to the database of the same name--- all
other apps spill over, via the PrimaryReplicaRouter(), to one of the other
databases and are migrated there. However, at the bottom of the page it
clearly states that "auth models — User, Group and Permission — are linked
together and linked to ContentType, so they must be stored in the same
database as ContentType". Thus, unless django_content_type is somehow
naturally given an app_label of 'auth', it would appear that this is a
contradiction.

The third matter is the 'default': {} recommendation. With several tries I
only get an error message to the effect that {} can't be empty.

In all it appears that the given code was never tested.

I can recommend a simple example, for which the painful "Example purposes
only!" disclaimer should be unnecessary. I am now happy with one database
being 'default':{...}, with the name of the database being also 'default'.
For that one I provide no router at all. For two others I use an
AuthRouter()-type that rigidly connects each of two apps of my own to a
corresponding database of the two. And so only the two routers for the two
databases are in the settings.py router chain.

With that, I have thrown away the migrations folders and checked to be
sure that the makemigrations-migrate sequence does the correct migrations.
It does--- the auth models and django_site, django_session,
django_migrations and django_content_type all end up in the 'default'
database; my models end up in the others.

Finally, "admin depends on auth, so their models must be in the same
database as auth" should be corrected (e.g. "its models").

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

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§§ āĻ¸ā§‡āĻĒ, ā§¨ā§Ļā§§ā§Ŧ, ā§¯:ā§Ģā§Ļ:ā§Šā§Ž AMā§§/ā§¯/ā§§ā§Ŧ
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Multiple problems with multiple database docs for 1.8 and possibly other
versions
-------------------------------------+-------------------------------------

Reporter: michaelcoconnor | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: multiple databases | Triage Stage:
docs | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Hi, we usually don't update old versions of the documentation except for
critical issues so as not to introduce untranslated text in the translated
versions of the docs. There have been some updates and corrections in
newer versions so if you could please check if these issues are relevant
in newer versions of the docs, that would be helpful.

1. What's the error and what are the steps to reproduce?
2. This might be valid. If you tested and confirmed it, feel free to
submit a correction.
3. Did you setup appropriate `DATABASE_ROUTERS` as described, "You must
setup DATABASE_ROUTERS for all of your apps’ models, including those in
any contrib and third-party apps you are using, so that no queries are
routed to the default database in order to do this." How do you reproduce
the issue?
4. We could certainly consider revising that example.

You've raised several issues which probably are best addressed in
different patches. For future reference, it's better to open separate
tickets rather than combining several different issues.

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

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§§ āĻ¸ā§‡āĻĒ, ā§¨ā§Ļā§§ā§Ŧ, ā§¯:ā§Ģā§Š:ā§Ģā§Ē AMā§§/ā§¯/ā§§ā§Ŧ
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Multiple problems with multiple database docs for 1.8 and possibly other
versions
-------------------------------------+-------------------------------------

Reporter: michaelcoconnor | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: multiple databases | Triage Stage:
docs | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@â€Ļ>):

In [changeset:"789f9c9b29dc79c3007b2b31cb75cf8d037f266d" 789f9c9b]:
{{{
#!CommitTicketReference repository=""
revision="789f9c9b29dc79c3007b2b31cb75cf8d037f266d"
Refs #27164 -- Fixed typo in docs/topics/db/multi-db.txt
}}}

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

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§§ āĻ¸ā§‡āĻĒ, ā§¨ā§Ļā§§ā§Ŧ, ā§¯:ā§Ģā§Ē:ā§Ļā§§ AMā§§/ā§¯/ā§§ā§Ŧ
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Multiple problems with multiple database docs for 1.8 and possibly other
versions
-------------------------------------+-------------------------------------

Reporter: michaelcoconnor | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: multiple databases | Triage Stage:
docs | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@â€Ļ>):

In [changeset:"2078b187f7f3d1985fd7457b4bd259fe1d75b8cb" 2078b187]:
{{{
#!CommitTicketReference repository=""
revision="2078b187f7f3d1985fd7457b4bd259fe1d75b8cb"
[1.10.x] Refs #27164 -- Fixed typo in docs/topics/db/multi-db.txt

Backport of 789f9c9b29dc79c3007b2b31cb75cf8d037f266d from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:3>

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§¨ āĻ¸ā§‡āĻĒ, ā§¨ā§Ļā§§ā§Ŧ, ā§§:ā§Ģā§Ŧ:ā§Ģā§§ AMā§¨/ā§¯/ā§§ā§Ŧ
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Multiple problems with multiple database docs for 1.8 and possibly other
versions
-------------------------------------+-------------------------------------

Reporter: michaelcoconnor | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: multiple databases | Triage Stage:
docs | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by michaelcoconnor):

Let's see you start on the rather evident--- no code examples needed
here--- contradiction between the fact that the AuthRouter() assigns all
auth models and only auth models to one database and the statement at the
bottom that "auth models — User, Group and Permission — are linked


together and linked to ContentType, so they must be stored in the same

database as ContentType." This ticket is in part about documentation,
writing--- not only about whether the given code example works or not.

That seeming conflict is in '''1.7 through to dev'''. Yes or no. Is this
not a glaring and absurd conflict (and a pain-inducing one at that for
those who are new to multiple databases)? Wouldn't the django_content_type
model end up in the second database, whereas the docs 1.7-dev all say it
must be stored in the same database as auth?

Since 1.9 discontinued support for FastCGI some hosting companies offering
shared-hosting (e.g., A2 Hosting, a "Django-friendly" company) are stalled
out at Django 1.8.7 for now. I think that you can revise the 1.8 docs.

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:4>

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§¨ āĻ¸ā§‡āĻĒ, ā§¨ā§Ļā§§ā§Ŧ, ā§¯:ā§§ā§­:ā§Ģā§Š AMā§¨/ā§¯/ā§§ā§Ŧ
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Database routers examples could be more realistic
-------------------------------------+-------------------------------------
Reporter: michaelcoconnor | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: multiple databases | Triage Stage: Accepted
docs |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* type: Bug => Cleanup/optimization
* component: Database layer (models, ORM) => Documentation
* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

I haven't made much use of multi-db support but at this point in my
understanding, only point 2 seems valid, so I'll accept the ticket for
that issue. If you can provide more details (steps to reproduce) about
points 1 and 3, then please open separate tickets. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:5>

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§§ āĻ¨āĻ­ā§‡, ā§¨ā§Ļā§§ā§¯, ā§¯:ā§¨ā§Ē:ā§§ā§Ē AMā§§/ā§§ā§§/ā§§ā§¯
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Database routers examples could be more realistic
-------------------------------------+-------------------------------------
Reporter: michaeloconnor | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: multiple databases | Triage Stage: Accepted
docs |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Caio Ariede):

* status: new => assigned
* owner: nobody => Caio Ariede


Comment:

I can see that the `AuthRouter` would not work in the
[https://docs.djangoproject.com/en/3.0/topics/db/multi-db/#an-example
provided example], given that a query for `Permission` that
[https://github.com/django/django/blob/stable/3.0.x/django/contrib/auth/models.py#L57-L61
has a relationship] with `ContentType` would not work.

It is not clear to me how to make that example work, given that, moving
`ContentType` to `auth_db` would create other restrictions for models
using `ContentType`.

Should we just replace this example with something else? Am I missing
something?

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:6>

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§§ā§Ž āĻ¨āĻ­ā§‡, ā§¨ā§Ļā§§ā§¯, ā§­:ā§Ēā§§:ā§Ēā§¯ AMā§§ā§Ž/ā§§ā§§/ā§§ā§¯
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Database routers examples could be more realistic
-------------------------------------+-------------------------------------
Reporter: michaeloconnor | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master

Severity: Normal | Resolution:
Keywords: multiple databases | Triage Stage: Accepted
docs |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Caio Ariede):

* has_patch: 0 => 1
* version: 1.8 => master


Comment:

[https://github.com/django/django/pull/12096 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:7>

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§¨ā§Ļ āĻ¨āĻ­ā§‡, ā§¨ā§Ļā§§ā§¯, ā§Ģ:ā§Ģā§Š:ā§§ā§§ AMā§¨ā§Ļ/ā§§ā§§/ā§§ā§¯
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Database routers examples could be more realistic
-------------------------------------+-------------------------------------
Reporter: michaeloconnor | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: multiple databases | Triage Stage: Accepted
docs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@â€Ļ>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"11e42001d9b4d91ad1f7161b7242ddff5457f56a" 11e42001]:
{{{
#!CommitTicketReference repository=""
revision="11e42001d9b4d91ad1f7161b7242ddff5457f56a"
[2.2.x] Fixed #27164 -- Fixed an example of using routers in multiple
databases docs.

Make sure that AuthRouter includes ContentType in the same database.

Backport of 608e06023e6eaf75f744134a0fd203853260e616 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:8>

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§¨ā§Ļ āĻ¨āĻ­ā§‡, ā§¨ā§Ļā§§ā§¯, ā§Ģ:ā§Ģā§Š:ā§§ā§¨ AMā§¨ā§Ļ/ā§§ā§§/ā§§ā§¯
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Database routers examples could be more realistic
-------------------------------------+-------------------------------------
Reporter: michaeloconnor | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: multiple databases | Triage Stage: Accepted
docs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@â€Ļ>):

In [changeset:"5f24b18e6cf052b7b6175d9d024bbd206c247be5" 5f24b18e]:
{{{
#!CommitTicketReference repository=""
revision="5f24b18e6cf052b7b6175d9d024bbd206c247be5"
[3.0.x] Fixed #27164 -- Fixed an example of using routers in multiple
databases docs.

Make sure that AuthRouter includes ContentType in the same database.

Backport of 608e06023e6eaf75f744134a0fd203853260e616 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:9>

Django

āĻĒā§œāĻž āĻšā§ŸāĻ¨āĻŋ,
ā§¨ā§Ļ āĻ¨āĻ­ā§‡, ā§¨ā§Ļā§§ā§¯, ā§Ģ:ā§Ģā§Š:ā§§ā§¨ AMā§¨ā§Ļ/ā§§ā§§/ā§§ā§¯
āĻĒā§āĻ°āĻžāĻĒāĻ• django-...@googlegroups.com
#27164: Database routers examples could be more realistic
-------------------------------------+-------------------------------------
Reporter: michaeloconnor | Owner: Caio
Type: | Ariede
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: multiple databases | Triage Stage: Accepted
docs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@â€Ļ>):

In [changeset:"608e06023e6eaf75f744134a0fd203853260e616" 608e0602]:
{{{
#!CommitTicketReference repository=""
revision="608e06023e6eaf75f744134a0fd203853260e616"


Fixed #27164 -- Fixed an example of using routers in multiple databases
docs.

Make sure that AuthRouter includes ContentType in the same database.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27164#comment:10>

āĻ¸āĻ•āĻ˛āĻ•ā§‡ āĻ‰āĻ¤ā§āĻ¤āĻ° āĻĻāĻŋāĻ¨
āĻ˛ā§‡āĻ–āĻ•āĻ•ā§‡ āĻ˛āĻŋāĻ–ā§‡ āĻĒāĻžāĻ āĻžāĻ¨
āĻĢāĻ°āĻ“ā§ŸāĻžāĻ°ā§āĻĄ āĻ•āĻ°ā§āĻ¨
0āĻŸāĻŋ āĻ¨āĻ¤ā§āĻ¨ āĻŽā§‡āĻ¸ā§‡āĻœ