Fixed #21453 -- Enabled autocommit before calling init_connection_state.

Also ensured the transaction state is clean on Oracle while I was there.

This change cannot be backported to 1.6 because it's
backwards-incompatible for custom database backends.
This commit is contained in:
Aymeric Augustin 2014-01-12 20:27:08 +01:00
parent c726598c3d
commit fbe1abac4a
4 changed files with 14 additions and 7 deletions

View File

@ -110,9 +110,8 @@ class BaseDatabaseWrapper(object):
# Establish the connection # Establish the connection
conn_params = self.get_connection_params() conn_params = self.get_connection_params()
self.connection = self.get_new_connection(conn_params) self.connection = self.get_new_connection(conn_params)
self.set_autocommit(self.settings_dict['AUTOCOMMIT'])
self.init_connection_state() self.init_connection_state()
if self.settings_dict['AUTOCOMMIT']:
self.set_autocommit(True)
connection_created.send(sender=self.__class__, connection=self) connection_created.send(sender=self.__class__, connection=self)
def ensure_connection(self): def ensure_connection(self):

View File

@ -627,6 +627,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
# Django docs specify cx_Oracle version 4.3.1 or higher, but # Django docs specify cx_Oracle version 4.3.1 or higher, but
# stmtcachesize is available only in 4.3.2 and up. # stmtcachesize is available only in 4.3.2 and up.
pass pass
# Ensure all changes are preserved even when AUTOCOMMIT is False.
if not self.get_autocommit():
self.commit()
def create_cursor(self): def create_cursor(self):
return FormatStylePlaceholderCursor(self.connection) return FormatStylePlaceholderCursor(self.connection)

View File

@ -142,12 +142,12 @@ class DatabaseWrapper(BaseDatabaseWrapper):
conn_tz = get_parameter_status('TimeZone') conn_tz = get_parameter_status('TimeZone')
if conn_tz != tz: if conn_tz != tz:
self.connection.cursor().execute( cursor = self.connection.cursor()
self.ops.set_time_zone_sql(), [tz] cursor.execute(self.ops.set_time_zone_sql(), [tz])
) cursor.close()
# Commit after setting the time zone (see #17062) # Commit after setting the time zone (see #17062)
self.connection.commit() if not self.get_autocommit():
self.connection.set_isolation_level(self.isolation_level) self.connection.commit()
def create_cursor(self): def create_cursor(self):
cursor = self.connection.cursor() cursor = self.connection.cursor()

View File

@ -899,6 +899,11 @@ Miscellaneous
* GeoDjango dropped support for GEOS < 3.1. * GeoDjango dropped support for GEOS < 3.1.
* The ``init_connection_state`` method of database backends now executes in
autocommit mode (unless you set :setting:`AUTOCOMMIT <DATABASE-AUTOCOMMIT>`
to ``False``). If you maintain a custom database backend, you should check
that method.
Features deprecated in 1.7 Features deprecated in 1.7
========================== ==========================