Commit ba5138b1 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Deprecated transaction.commit/rollback_unless_managed.

Since "unless managed" now means "if database-level autocommit",
committing or rolling back doesn't have any effect.

Restored transactional integrity in a few places that relied on
automatically-started transactions with a transitory API.
parent 14aa563f
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -555,10 +555,6 @@ class LayerMapping(object):
                    except SystemExit:
                        raise
                    except Exception as msg:
                        if self.transaction_mode == 'autocommit':
                            # Rolling back the transaction so that other model saves
                            # will work.
                            transaction.rollback_unless_managed()
                        if strict:
                            # Bailing out if the `strict` keyword is set.
                            if not silent:
+0 −1
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ class SessionStore(SessionBase):
    @classmethod
    def clear_expired(cls):
        Session.objects.filter(expire_date__lt=timezone.now()).delete()
        transaction.commit_unless_managed()


# At bottom to avoid circular import
+1 −6
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ except ImportError:

from django.conf import settings
from django.core.cache.backends.base import BaseCache
from django.db import connections, router, transaction, DatabaseError
from django.db import connections, router, DatabaseError
from django.utils import timezone, six
from django.utils.encoding import force_bytes

@@ -70,7 +70,6 @@ class DatabaseCache(BaseDatabaseCache):
            cursor = connections[db].cursor()
            cursor.execute("DELETE FROM %s "
                           "WHERE cache_key = %%s" % table, [key])
            transaction.commit_unless_managed(using=db)
            return default
        value = connections[db].ops.process_clob(row[1])
        return pickle.loads(base64.b64decode(force_bytes(value)))
@@ -124,10 +123,8 @@ class DatabaseCache(BaseDatabaseCache):
                               [key, b64encoded, connections[db].ops.value_to_db_datetime(exp)])
        except DatabaseError:
            # To be threadsafe, updates/inserts are allowed to fail silently
            transaction.rollback_unless_managed(using=db)
            return False
        else:
            transaction.commit_unless_managed(using=db)
            return True

    def delete(self, key, version=None):
@@ -139,7 +136,6 @@ class DatabaseCache(BaseDatabaseCache):
        cursor = connections[db].cursor()

        cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key])
        transaction.commit_unless_managed(using=db)

    def has_key(self, key, version=None):
        key = self.make_key(key, version=version)
@@ -184,7 +180,6 @@ class DatabaseCache(BaseDatabaseCache):
        table = connections[db].ops.quote_name(self._table)
        cursor = connections[db].cursor()
        cursor.execute('DELETE FROM %s' % table)
        transaction.commit_unless_managed(using=db)

# For backwards compatibility
class CacheClass(DatabaseCache):
+10 −11
Original line number Diff line number Diff line
@@ -53,14 +53,13 @@ class Command(LabelCommand):
        for i, line in enumerate(table_output):
            full_statement.append('    %s%s' % (line, i < len(table_output)-1 and ',' or ''))
        full_statement.append(');')
        with transaction.commit_on_success_unless_managed():
            curs = connection.cursor()
            try:
                curs.execute("\n".join(full_statement))
            except DatabaseError as e:
            transaction.rollback_unless_managed(using=db)
                raise CommandError(
                    "Cache table '%s' could not be created.\nThe error was: %s." %
                        (tablename, force_text(e)))
            for statement in index_output:
                curs.execute(statement)
        transaction.commit_unless_managed(using=db)
+4 −5
Original line number Diff line number Diff line
@@ -57,18 +57,17 @@ Are you sure you want to do this?

        if confirm == 'yes':
            try:
                with transaction.commit_on_success_unless_managed():
                    cursor = connection.cursor()
                    for sql in sql_list:
                        cursor.execute(sql)
            except Exception as e:
                transaction.rollback_unless_managed(using=db)
                raise CommandError("""Database %s couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: %s""" % (connection.settings_dict['NAME'], e))
            transaction.commit_unless_managed(using=db)

            # Emit the post sync signal. This allows individual
            # applications to respond as if the database had been
Loading