Commit 4edbb8b2 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Refs #8138 -- Added a stealth option to the loaddata command so that the use...

Refs #8138 -- Added a stealth option to the loaddata command so that the use of transactions in loaddata can be disabled. This behavior isn't enabled as a commad line option because it doesn't make much sense, but it can be used when invoking loaddata from another script.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8336 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent cb1368bb
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -29,6 +29,14 @@ class Command(BaseCommand):
        verbosity = int(options.get('verbosity', 1))
        show_traceback = options.get('traceback', False)
        
        # commit is a stealth option - it isn't really useful as 
        # a command line option, but it can be useful when invoking
        # loaddata from within another script. 
        # If commit=True, loaddata will use its own transaction;
        # if commit=False, the data load SQL will become part of
        # the transaction in place when loaddata was invoked.
        commit = options.get('commit', True)
        
        # Keep a count of the installed objects and fixtures
        fixture_count = 0
        object_count = 0
@@ -44,6 +52,7 @@ class Command(BaseCommand):

        # Start transaction management. All fixtures are installed in a
        # single transaction to ensure that all references are resolved.
        if commit:
            transaction.commit_unless_managed()
            transaction.enter_transaction_management()
            transaction.managed(True)
@@ -153,6 +162,7 @@ class Command(BaseCommand):
                for line in sequence_sql:
                    cursor.execute(line)
        
        if commit:
            transaction.commit()
            transaction.leave_transaction_management()

@@ -167,4 +177,5 @@ class Command(BaseCommand):
        # edge case in MySQL: if the same connection is used to
        # create tables, load data, and query, the query can return
        # incorrect results. See Django #7572, MySQL #37735.
        if commit:
            connection.close()