#12171: transaction.savepoint_rollback fails with postgresql DATABASE_ENGINE
---------------------------------------------------+------------------------
          Reporter:  andrewbadr                    |         Owner:  nobody
            Status:  new                           |     Milestone:  1.2   
         Component:  Database layer (models, ORM)  |       Version:  1.1   
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  0     
        Needs_docs:  0                             |   Needs_tests:  0     
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by kmtracey):

 I can't figure out how you are even getting to the point where
 `get_or_create` tries to rollback the transaction. At the revision
 mentioned (and now), `get_or_create` only tries the rollback when it
 catches an !IntegrityError (see
 
http://code.djangoproject.com/browser/django/trunk/django/db/models/query.py?rev=11724#L311).
 Yet when I try to run the `get_or_create` testcase with the old postgres
 backend, the first problem encountered is that no !IntegrityError is
 raised but rather a !ProgrammingError is raised. (This is true even with
 1.1 or trunk r11724). I have to change the `except IntegrityError, e` in
 `get_or_create` to `except Exception, e` and then I can see the subsequent
 problem that attempting to do a savepoint rollback will first try to set
 do that "SET client_encoding to 'UNICODE'":

 {{{
 > c:\u\kmt\django\django-1.1\django\test\_doctest.py(362)set_trace()->None
 -> pdb.Pdb.set_trace(self)
 (Pdb) n
 > c:\u\kmt\django\django-1.1\django\db\models\query.py(341)get_or_create()
 -> transaction.savepoint_rollback(sid)
 (Pdb) l
 336                     transaction.savepoint_commit(sid)
 337                     return obj, True
 338     #           except IntegrityError, e:
 339                 except Exception, e:
 340                     import pdb; pdb.set_trace()
 341  ->                 transaction.savepoint_rollback(sid)
 342                     try:
 343                         return self.get(**kwargs), False
 344                     except self.model.DoesNotExist:
 345                         raise e
 346
 (Pdb) n
 ProgrammingError: "ERROR:  current transaction is aborted, commands
 ignored until end of transaction block\n\nSET client
 _encoding to 'UNICODE'"
 > c:\u\kmt\django\django-1.1\django\db\models\query.py(341)get_or_create()
 -> transaction.savepoint_rollback(sid)
 (Pdb)
 }}}

 So, a question: have you done anything to your install to fix this
 !IntegrityError/!ProgrammingError mismatch I see? I'm also wondering why
 you are using the old backend instead of psycopg2?

 The error I see is reported in #12766 but since this is a bit different
 I'm going to leave both open for now.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12171#comment:9>
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-upda...@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