Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 536ccd1134d747bc22cf80c42c332e533146a9fe 1 parent 0597dea
Malcolm Tredinnick authored March 16, 2009
14  django/db/backends/postgresql_psycopg2/base.py
@@ -29,7 +29,7 @@
29 29
 
30 30
 class DatabaseFeatures(BaseDatabaseFeatures):
31 31
     needs_datetime_string_cast = False
32  
-    can_return_id_from_insert = True
  32
+    can_return_id_from_insert = False
33 33
 
34 34
 class DatabaseOperations(PostgresqlDatabaseOperations):
35 35
     def last_executed_query(self, cursor, sql, params):
@@ -105,15 +105,17 @@ def _cursor(self):
105 105
             if self._version < (8, 0):
106 106
                 # No savepoint support for earlier version of PostgreSQL.
107 107
                 self.features.uses_savepoints = False
108  
-            if self._version < (8, 2):
109  
-                # Cannot return the insert ID as part of an INSERT statement
110  
-                # prior to version 8.2.
111  
-                self.features.can_return_id_from_insert = False
112  
-                if self.features.uses_autocommit:
  108
+            if self.features.uses_autocommit:
  109
+                if self._version < (8, 2):
113 110
                     # FIXME: Needs extra code to do reliable model insert
114 111
                     # handling, so we forbid it for now.
115 112
                     from django.core.exceptions import ImproperlyConfigured
116 113
                     raise ImproperlyConfigured("You cannot use autocommit=True with PostgreSQL prior to 8.2 at the moment.")
  114
+                else:
  115
+                    # FIXME: Eventually we're enable this by default for
  116
+                    # versions that support it, but, right now, that's hard to
  117
+                    # do without breaking other things (#10509).
  118
+                    self.features.can_return_id_from_insert = True
117 119
         return cursor
118 120
 
119 121
     def _enter_transaction_management(self, managed):

0 notes on commit 536ccd1

Please sign in to comment.
Something went wrong with that request. Please try again.