Ticket #3460: 3460-r8961-autocommit.diff
File 3460-r8961-autocommit.diff, 5.6 KB (added by , 16 years ago) |
---|
-
django/db/backends/postgresql/base.py
96 96 self.validation = BaseDatabaseValidation() 97 97 98 98 def _cursor(self, settings): 99 set_tz= False99 first_cursor = False 100 100 if self.connection is None: 101 set_tz= True101 first_cursor = True 102 102 if settings.DATABASE_NAME == '': 103 103 from django.core.exceptions import ImproperlyConfigured 104 104 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") … … 112 112 if settings.DATABASE_PORT: 113 113 conn_string += " port=%s" % settings.DATABASE_PORT 114 114 self.connection = Database.connect(conn_string, **self.options) 115 self.connection.set_isolation_level( 1) # make transactions transparent to all cursors115 self.connection.set_isolation_level(0) 116 116 cursor = self.connection.cursor() 117 if set_tz:117 if first_cursor: 118 118 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 119 cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED") 120 self._commit() 119 121 if not hasattr(self, '_version'): 120 122 self.__class__._version = get_version(cursor) 121 123 if self._version < (8, 0): -
django/db/backends/postgresql_psycopg2/base.py
66 66 self.validation = BaseDatabaseValidation() 67 67 68 68 def _cursor(self, settings): 69 set_tz= False69 first_cursor = False 70 70 if self.connection is None: 71 set_tz= True71 first_cursor = True 72 72 if settings.DATABASE_NAME == '': 73 73 from django.core.exceptions import ImproperlyConfigured 74 74 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") … … 82 82 if settings.DATABASE_PORT: 83 83 conn_string += " port=%s" % settings.DATABASE_PORT 84 84 self.connection = Database.connect(conn_string, **self.options) 85 self.connection.set_isolation_level( 1) # make transactions transparent to all cursors85 self.connection.set_isolation_level(0) 86 86 self.connection.set_client_encoding('UTF8') 87 87 cursor = self.connection.cursor() 88 88 cursor.tzinfo_factory = None 89 if set_tz:89 if first_cursor: 90 90 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 91 cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED") 92 self._commit() 91 93 if not hasattr(self, '_version'): 92 94 self.__class__._version = get_version(cursor) 93 95 if self._version < (8, 0): -
django/db/transaction.py
185 185 savepoint_state[thread_ident] = [None] 186 186 tid = str(thread_ident).replace('-', '') 187 187 sid = "s%s_x%d" % (tid, len(savepoint_state[thread_ident])) 188 connection._savepoint(sid) 188 if is_managed(): 189 connection._savepoint(sid) 189 190 return sid 190 191 191 192 def savepoint_rollback(sid): … … 194 195 savepoints are not supported. 195 196 """ 196 197 if thread.get_ident() in savepoint_state: 197 connection._savepoint_rollback(sid) 198 if is_managed(): 199 connection._savepoint_rollback(sid) 198 200 199 201 def savepoint_commit(sid): 200 202 """ … … 202 204 savepoints are not supported. 203 205 """ 204 206 if thread.get_ident() in savepoint_state: 205 connection._savepoint_commit(sid) 207 if is_managed(): 208 connection._savepoint_commit(sid) 206 209 207 210 ############## 208 211 # DECORATORS # -
django/core/management/commands/loaddata.py
9 9 except NameError: 10 10 from sets import Set as set # Python 2.3 fallback 11 11 12 def _set_transaction_mode(connection): 13 "Make sure a connection is not in autocommit mode." 14 if hasattr(connection.connection, "autocommit"): 15 connection.connection.autocommit(False) 16 elif hasattr(connection.connection, "set_isolation_level"): 17 connection.connection.set_isolation_level(1) 18 12 19 class Command(BaseCommand): 13 20 option_list = BaseCommand.option_list + ( 14 21 make_option('--verbosity', action='store', dest='verbosity', default='1', … … 49 56 # the side effect of initializing the test database (if 50 57 # it isn't already initialized). 51 58 cursor = connection.cursor() 59 _set_transaction_mode(connection) 52 60 53 61 # Start transaction management. All fixtures are installed in a 54 62 # single transaction to ensure that all references are resolved. … … 177 185 # edge case in MySQL: if the same connection is used to 178 186 # create tables, load data, and query, the query can return 179 187 # incorrect results. See Django #7572, MySQL #37735. 188 # Also used to ensure _set_transaction_mode does not leak out 180 189 if commit: 181 190 connection.close()