Opened 10 years ago

Closed 10 years ago

#24579 closed Uncategorized (wontfix)

With argparse on Python 3, the migrate management command fails when no database provided

Reported by: Brandon Konkle Owned by: nobody
Component: Uncategorized Version: 1.8
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

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.

Change History (3)

comment:1 by Brandon Konkle, 10 years ago

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'.

comment:2 by Brandon Konkle, 10 years ago

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.

comment:3 by Brandon Konkle, 10 years ago

Resolution: wontfix
Status: newclosed

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.

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