Ticket #16743: 16743-1.diff

File 16743-1.diff, 2.0 KB (added by Claude Paroz, 13 years ago)

Late loading of db module in dumpdata command

  • django/core/management/commands/dumpdata.py

    diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
    index 1622929..1f89dfd 100644
    a b  
    11from django.core.exceptions import ImproperlyConfigured
    22from django.core.management.base import BaseCommand, CommandError
    3 from django.core import serializers
    4 from django.db import router, DEFAULT_DB_ALIAS
    53from django.utils.datastructures import SortedDict
    64
    75from optparse import make_option
    class Command(BaseCommand):  
    1311        make_option('--indent', default=None, dest='indent', type='int',
    1412            help='Specifies the indent level to use when pretty-printing output'),
    1513        make_option('--database', action='store', dest='database',
    16             default=DEFAULT_DB_ALIAS, help='Nominates a specific database to dump '
     14            help='Nominates a specific database to dump '
    1715                'fixtures from. Defaults to the "default" database.'),
    1816        make_option('-e', '--exclude', dest='exclude',action='append', default=[],
    1917            help='An appname or appname.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).'),
    class Command(BaseCommand):  
    2826    args = '[appname appname.ModelName ...]'
    2927
    3028    def handle(self, *app_labels, **options):
     29        # Late imports to be able to get command help even when DATABASES
     30        # setting contains errors
     31        from django.core import serializers
    3132        from django.db.models import get_app, get_apps, get_model
     33        from django.db import router, DEFAULT_DB_ALIAS
    3234
    3335        format = options.get('format')
    3436        indent = options.get('indent')
    35         using = options.get('database')
     37        using = options.get('database', DEFAULT_DB_ALIAS)
    3638        excludes = options.get('exclude')
    3739        show_traceback = options.get('traceback')
    3840        use_natural_keys = options.get('use_natural_keys')
Back to Top