More fixing of PostgreSQL < 8.2 problems with the psycopg2 backend.
Affects the postgresql_psycopg2 backend only. We now don't use the "RETURNING" syntax in SQL INSERT statements unless it's required by the autocommit behaviour. This fixes an edge-case that could cause crashes with earlier PostgreSQL versions, but the broader problem remains to be fixed (which is #10509). Fixed #10467. Refs #10509. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10065 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0597dea4d0
commit
536ccd1134
|
@ -29,7 +29,7 @@ psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedStri
|
||||||
|
|
||||||
class DatabaseFeatures(BaseDatabaseFeatures):
|
class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
needs_datetime_string_cast = False
|
needs_datetime_string_cast = False
|
||||||
can_return_id_from_insert = True
|
can_return_id_from_insert = False
|
||||||
|
|
||||||
class DatabaseOperations(PostgresqlDatabaseOperations):
|
class DatabaseOperations(PostgresqlDatabaseOperations):
|
||||||
def last_executed_query(self, cursor, sql, params):
|
def last_executed_query(self, cursor, sql, params):
|
||||||
|
@ -105,15 +105,17 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
if self._version < (8, 0):
|
if self._version < (8, 0):
|
||||||
# No savepoint support for earlier version of PostgreSQL.
|
# No savepoint support for earlier version of PostgreSQL.
|
||||||
self.features.uses_savepoints = False
|
self.features.uses_savepoints = False
|
||||||
if self._version < (8, 2):
|
if self.features.uses_autocommit:
|
||||||
# Cannot return the insert ID as part of an INSERT statement
|
if self._version < (8, 2):
|
||||||
# prior to version 8.2.
|
|
||||||
self.features.can_return_id_from_insert = False
|
|
||||||
if self.features.uses_autocommit:
|
|
||||||
# FIXME: Needs extra code to do reliable model insert
|
# FIXME: Needs extra code to do reliable model insert
|
||||||
# handling, so we forbid it for now.
|
# handling, so we forbid it for now.
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
raise ImproperlyConfigured("You cannot use autocommit=True with PostgreSQL prior to 8.2 at the moment.")
|
raise ImproperlyConfigured("You cannot use autocommit=True with PostgreSQL prior to 8.2 at the moment.")
|
||||||
|
else:
|
||||||
|
# FIXME: Eventually we're enable this by default for
|
||||||
|
# versions that support it, but, right now, that's hard to
|
||||||
|
# do without breaking other things (#10509).
|
||||||
|
self.features.can_return_id_from_insert = True
|
||||||
return cursor
|
return cursor
|
||||||
|
|
||||||
def _enter_transaction_management(self, managed):
|
def _enter_transaction_management(self, managed):
|
||||||
|
|
Loading…
Reference in New Issue