#32527: needs_rollback flag issue with implementation of backend that does not
support savepoint
-------------------------------------+-------------------------------------
               Reporter:  Hemant     |          Owner:  nobody
  Bhanawat                           |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  dev
  layer (models, ORM)                |       Keywords:  savepoint
               Severity:  Normal     |  needs_rollback database backend
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I am implementing a backend for Yugabyte. Yugabyte currently doesn't
 support savepoints. Hence, in the backend, I have set uses_savepoints=
 False

 However, while running the test. I hit the following issue.

 The error: "TransactionManagementError: An error occurred in the current
 transaction. You can't execute queries until the end of the 'atomic'
 block."

 On some investigation, I found that this exception is thrown if
 self.needs_rollback is True. The first test that uses savepoint passes
 successfully. However, the second test has needs_rollback set as true and
 hits this exception.

 The problem stems from the following code of __enter__ function in
 transaction.py

             if self.savepoint and not connection.needs_rollback:
                 sid = connection.savepoint()
                 connection.savepoint_ids.append(sid)
             else:
                 connection.savepoint_ids.append(None)

 Basically, a None is inserted in the savepoint_ids when the savepoints are
 not supported. And the following code in __exit__ function of
 transaction.py, it sets needs_rollback as true:

                     if sid is None:
                         connection.needs_rollback = True

 Can someone please clarify if this is an issue with the code or there is
 something else that we can do at our layer. For the time being, we have
 overridden the function savepoint of DatabaseWrapper to return 1. And, we
 ask the users of our backend to not set savepoint=true in parameters of
 transaction.atomic().

     def savepoint(self):
              return 1

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32527>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.9be6ad20908610df5b251a4121e10ef1%40djangoproject.com.

Reply via email to