[Django] #24579: With argparse on Python 3, the migrate management command fails when no database provided

15 views
Skip to first unread message

Django

unread,
Apr 3, 2015, 5:15:11 PM4/3/15
to django-...@googlegroups.com
#24579: With argparse on Python 3, the migrate management command fails when no
database provided
-------------------------------+--------------------
Reporter: bkonkle | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
On Python 3.4, when 'migrate' is invoked with no --database option, the
command fails.

{{{
File
"/Users/brandon.konkle/code/django/django/core/management/commands/migrate.py",
line 70, in handle
connection = connections[db]
File "/Users/brandon.konkle/code/django/django/db/utils.py", line 234,
in __getitem__
if hasattr(self._connections, alias):
TypeError: hasattr(): attribute name must be string
}}}

This is because the newly-introduced argparse resolves `db =
options.get('database')` to `None`, and Python 3 raises a TypeError when
None is used as the first argument to `hasattr`.

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

Django

unread,
Apr 3, 2015, 5:22:54 PM4/3/15
to django-...@googlegroups.com
#24579: With argparse on Python 3, the migrate management command fails when no
database provided
-------------------------------+--------------------------------------

Reporter: bkonkle | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
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
-------------------------------+--------------------------------------
Changes (by bkonkle):

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


Comment:

Hmm, argparse actually shouldn't be resolving this to `None`, because the
--database option has a default set: `default=DEFAULT_DB_ALIAS`, which is
'default'.

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

Django

unread,
Apr 3, 2015, 5:32:43 PM4/3/15
to django-...@googlegroups.com
#24579: With argparse on Python 3, the migrate management command fails when no
database provided
-------------------------------+--------------------------------------

Reporter: bkonkle | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
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
-------------------------------+--------------------------------------

Comment (by bkonkle):

For some reason, the the migrate command is showing up as having an
option_list, so it's not calling the add_arguments() method and setting up
the default.

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

Django

unread,
Apr 3, 2015, 5:36:57 PM4/3/15
to django-...@googlegroups.com
#24579: With argparse on Python 3, the migrate management command fails when no
database provided
-------------------------------+--------------------------------------
Reporter: bkonkle | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution: wontfix
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 bkonkle):

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


Comment:

Aha! This is a side-effect of `django-configurations` adding the
--configuration option to the base management command. I'll submit a pull
request there.

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

Reply all
Reply to author
Forward
0 new messages