[Django] #23102: SQL-Management does not work with DATABASE_ROUTERS set

19 views
Skip to first unread message

Django

unread,
Jul 25, 2014, 5:19:14 PM7/25/14
to django-...@googlegroups.com
#23102: SQL-Management does not work with DATABASE_ROUTERS set
--------------------------------------------+----------------------
Reporter: manuel.gysin@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management commands) | Version: 1.7-rc-1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------------+----------------------
Hello,

If you set DATABASE_ROUTERS in settings.py, none of the sql-management
commands are working:

{{{
[root@dgweb Demo]# python manage.py sqlall SampleModel
[root@dgweb Demo]#
[root@dgweb Demo]# python manage.py sql SampleMode
[root@dgweb Demo]#
}}}

As soon DATABASE_ROUTERS is removed, things start working again:

{{{
[root@dgweb Demo]# python manage.py sqlall SampleModel
BEGIN;
CREATE TABLE "SampleModel_location" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" varchar(50) NOT NULL
)
;

COMMIT;
}}}

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

Django

unread,
Jul 26, 2014, 5:16:14 AM7/26/14
to django-...@googlegroups.com
#23102: SQL-Management does not work with DATABASE_ROUTERS set
-------------------------------------+-------------------------------------
Reporter: manuel.gysin@… | Owner: nobody
Type: Bug | Status: closed
Component: Core (Management | Version: 1.7-rc-1
commands) | Resolution: needsinfo
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* needs_better_patch: => 0
* resolution: => needsinfo
* needs_tests: => 0
* needs_docs: => 0


Comment:

I guess this might be related to the content of your `DATABASE_ROUTERS`
setting. The best way to prove us the presence of a bug would be to
provide a sample project where this can be reproduced.

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

Django

unread,
Jul 26, 2014, 10:27:10 AM7/26/14
to django-...@googlegroups.com
#23102: SQL-Management does not work with DATABASE_ROUTERS set
-------------------------------------+-------------------------------------

Reporter: manuel.gysin@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.7-rc-1
commands) | Resolution:

Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: closed => new
* resolution: needsinfo =>


Comment:

Hello

No it have nothing to do with the setting itself.
There is a different behavior between Django 1.6 and 1.7.

This gives no output, because SampleModel in the second_db.
{{{
[mgysin@localhost Demo]$ python manage.py sqlall SampleModel
[mgysin@localhost Demo]$
}}}

Adjusting the command with --database argument, get things working again:

{{{
[mgysin@localhost Demo]$ python manage.py sqlall SampleModel
--database=second_db


BEGIN;
CREATE TABLE "SampleModel_location" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" varchar(50) NOT NULL
)
;

COMMIT;
}}}

I'm not sure if this is a design decision or just some side effect with
Django 1.7.
But it is very confusing if you are not aware of that. Maybe something
like 'Only models in the default database are used, for other databases
please provide --database argument' should be printed?

I've added an demo sample with this behavior.

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

Django

unread,
Jul 26, 2014, 12:15:22 PM7/26/14
to django-...@googlegroups.com
#23102: SQL-Management does not work with DATABASE_ROUTERS set
-------------------------------------+-------------------------------------

Reporter: manuel.gysin@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.7-rc-1
commands) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by areski):

It's definitely a change of behaviour in Django 1.7.

In 1.7 we read the models from router.get_migratable_models:
https://github.com/django/django/blob/master/django/core/management/sql.py#L45
in 1.6 we read the models from models.get_models:
https://github.com/django/django/blob/1.6.5/django/core/management/sql.py

I'm not sure what's the desired implementation for 1.7

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

Django

unread,
Jul 26, 2014, 12:34:22 PM7/26/14
to django-...@googlegroups.com
#23102: Document change in manage.py sql* --database behavior in 1.7
--------------------------------------+------------------------------------
Reporter: manuel.gysin@… | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
* component: Core (Management commands) => Documentation


Comment:

The new behavior makes sense to me. I think we should clarify the
documentation and add a note about it in the 1.7 release notes.

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

Django

unread,
Jul 26, 2014, 9:50:50 PM7/26/14
to django-...@googlegroups.com
#23102: Document change in manage.py sql* --database behavior in 1.7
--------------------------------------+------------------------------------
Reporter: manuel.gysin@… | Owner: gmunumel
Type: Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: nobody => gmunumel
* status: new => assigned


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

Django

unread,
Jul 27, 2014, 12:51:55 AM7/27/14
to django-...@googlegroups.com
#23102: Document change in manage.py sql* --database behavior in 1.7
--------------------------------------+------------------------------------
Reporter: manuel.gysin@… | Owner: gmunumel
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by gmunumel):

I made the change in release notes for 1.7 version but I cannot get the
commit working. I followed the
[https://docs.djangoproject.com/en/1.6/internals/contributing/writing-code
/working-with-git/ documentation], but on commit I got an error: {{{fatal:
unable to access 'https://github.com/django/django.git/': The requested
URL returned error: 403}}}. I'm new on this, :(

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

Django

unread,
Jul 27, 2014, 2:40:17 PM7/27/14
to django-...@googlegroups.com
#23102: Document change in manage.py sql* --database behavior in 1.7
--------------------------------------+------------------------------------
Reporter: manuel.gysin@… | Owner: gmunumel
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* cc: areski@… (added)


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

Django

unread,
Jul 28, 2014, 9:54:35 AM7/28/14
to django-...@googlegroups.com
#23102: Document change in manage.py sql* --database behavior in 1.7
-------------------------------------+-------------------------------------
Reporter: manuel.gysin@… | Owner: gmunumel
Type: | Status: assigned
Cleanup/optimization | Version: 1.7-rc-1
Component: Documentation | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

Don't forget to check the "Has patch" flag so the ticket appears in the
review queue. I'll review and commit this now. Thanks.

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

Django

unread,
Jul 28, 2014, 10:06:38 AM7/28/14
to django-...@googlegroups.com
#23102: Document change in manage.py sql* --database behavior in 1.7
-------------------------------------+-------------------------------------
Reporter: manuel.gysin@… | Owner: gmunumel
Type: | Status: closed
Cleanup/optimization | Version: 1.7-rc-1
Component: Documentation | Resolution: fixed

Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"2077bbe3fefb58eadfde0f2f36af13a0f1d3704a"]:
{{{
#!CommitTicketReference repository=""
revision="2077bbe3fefb58eadfde0f2f36af13a0f1d3704a"
[1.7.x] Fixed #23102 -- Documented that sql* commands now respect
allow_migrate().

Backport of 0af593dbe5 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages