Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32527 closed Bug (duplicate)

needs_rollback flag issue with implementation of backend that does not support savepoint — at Version 1

Reported by: Hemant Bhanawat Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: savepoint needs_rollback database backend
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

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 

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Description: modified (diff)
Resolution: needsinfo
Status: newclosed

Thanks for this report, however I'm not able to confirm (with the given details) that it is an issue in Django. As far as I'm aware it should work properly. In Django < 2.0 we supported SQLite < 3.7.5 with the same configuration (see 27193aea0088b238e3ee0f0f235364a34a09265c) and it worked fine. You can try to create a topic on the https://forum.djangoproject.com or a discussion on DevelopersMailingList.

Feel-free to reopen the ticket when you can provide more details and prove it's an issue in Django.

Note: See TracTickets for help on using tickets.
Back to Top