Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: override django autocommit to spanner #583

Merged
merged 2 commits into from Jan 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")