Ticket #16047: 1-supports-transactions.patch

File 1-supports-transactions.patch, 1.8 KB (added by Brodie Rao, 13 years ago)
  • django/db/backends/__init__.py

    # HG changeset patch
    # User Brodie Rao <brodie@bitheap.org>
    # Date 1305680847 25200
    # Node ID 95cddfdbec66b6851789d8bce7257b46de1dec41
    # Parent  fcf918fa9b40cf7570c280996f9dc164a2b0c17a
    db: fix transaction support detection when using psycopg2 with autocommit
    
    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    a b class BaseDatabaseFeatures(object):  
    421421
    422422    def _supports_transactions(self):
    423423        "Confirm support for transactions"
    424         cursor = self.connection.cursor()
    425         cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
    426         self.connection._commit()
    427         cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
    428         self.connection._rollback()
    429         cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST')
    430         count, = cursor.fetchone()
    431         cursor.execute('DROP TABLE ROLLBACK_TEST')
    432         self.connection._commit()
    433         return count == 0
     424        managed = self.connection.is_managed()
     425        self.connection.enter_transaction_management()
     426        self.connection.managed(True)
     427        try:
     428            cursor = self.connection.cursor()
     429            cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
     430            self.connection.commit()
     431            cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
     432            self.connection.rollback()
     433            cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST')
     434            count, = cursor.fetchone()
     435            cursor.execute('DROP TABLE ROLLBACK_TEST')
     436            self.connection.commit()
     437            return count == 0
     438        finally:
     439            self.connection.managed(managed)
     440            self.connection.leave_transaction_management()
    434441
    435442    def _supports_stddev(self):
    436443        "Confirm support for STDDEV and related stats functions"
Back to Top