Skip to content

Commit

Permalink
fix: override django autocommit to spanner (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
HemangChothani committed Jan 29, 2021
1 parent 59ce5e7 commit 7ce685d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions django_spanner/base.py
Expand Up @@ -156,9 +156,11 @@ def get_new_connection(self, conn_params):

def init_connection_state(self):
"""Initialize the state of the existing connection."""
autocommit = self.connection.autocommit
self.connection.close()
database = self.connection.database
self.connection.__init__(self.instance, database)
self.connection.autocommit = autocommit

def create_cursor(self, name=None):
"""Create a new Database cursor.
Expand Down Expand Up @@ -196,3 +198,12 @@ def is_usable(self):
return False

return True

def _start_transaction_under_autocommit(self):
"""
Start a transaction explicitly in autocommit mode.
Staying in autocommit mode works around a bug that breaks
save points when autocommit is disabled by django.
"""
self.connection.cursor().execute("SELECT 1")

0 comments on commit 7ce685d

Please sign in to comment.