#10467: Remove use of "RETURNING" in PostgreSQL backends by default
---------------------------------------------------+------------------------
          Reporter:  mtredinnick                   |         Owner:  mtredinnick
            Status:  reopened                      |     Milestone:  1.1 beta   
         Component:  Database layer (models, ORM)  |       Version:  1.0        
        Resolution:                                |      Keywords:             
             Stage:  Unreviewed                    |     Has_patch:  0          
        Needs_docs:  0                             |   Needs_tests:  0          
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by offmessage):

  * status:  closed => reopened
  * resolution:  fixed =>

Comment:

 I'm afraid this one isn't quite fixed.  If the ''very first'' database
 operation on a connection is a {{{save()}}} you still get the error
 reporting in #10474: {{{syntax error at or near "RETURNING"}}}. It looks
 like the test for PostgreSQL version is only done at the point a query is
 issued. I'm afraid I'm new to Django and haven't been able to propose a
 patch.

 Simple test case:
 {{{
 >>> from django.db import connection
 >>> connection.features.can_return_id_from_insert
 True
 >>> connection._version
 Traceback (most recent call last):
   File "<console>", line 1, in ?
 AttributeError: 'DatabaseWrapper' object has no attribute '_version'
 >>> from test.test.models import TestCase
 >>> t = TestCase(teststring="hello")
 >>> t.save()
 Traceback (most recent call last):
   File "<console>", line 1, in ?
   File
 "/home/andy/projects/django10474/code/django/django/db/models/base.py",
 line 330, in save
     self.save_base(force_insert=force_insert, force_update=force_update)
   File
 "/home/andy/projects/django10474/code/django/django/db/models/base.py",
 line 402, in save_base
     result = manager._insert(values, return_id=update_pk)
   File
 "/home/andy/projects/django10474/code/django/django/db/models/manager.py",
 line 168, in _insert
     return insert_query(self.model, values, **kwargs)
   File
 "/home/andy/projects/django10474/code/django/django/db/models/query.py",
 line 1054, in insert_query
     return query.execute_sql(return_id)
   File
 
"/home/andy/projects/django10474/code/django/django/db/models/sql/subqueries.py",
 line 320, in execute_sql
     cursor = super(InsertQuery, self).execute_sql(None)
   File
 "/home/andy/projects/django10474/code/django/django/db/models/sql/query.py",
 line 2098, in execute_sql
     cursor.execute(sql, params)
   File
 "/home/andy/projects/django10474/code/django/django/db/backends/util.py",
 line19, in execute
     return self.cursor.execute(sql, params)
 ProgrammingError: syntax error at or near "RETURNING" at character 63
 }}}

 and

 {{{
 >>> from django.db import connection
 >>> connection.features.can_return_id_from_insert
 True
 >>> from test.test.models import TestCase
 >>> TestCase.objects.all()
 []
 >>> connection._version
 (8, 1)
 >>> connection.features.can_return_id_from_insert
 False
 >>> t = TestCase(teststring="hello")
 >>> t.save()
 >>>
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10467#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to