From 7c183c00ad57d29f8b703a7cdbfd4878ea9451c5 Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Wed, 22 Feb 2023 14:14:30 -0500 Subject: [PATCH] fix(cloudsql): make connections commit as you go (#9160) --- cloud-sql/mysql/sqlalchemy/app.py | 2 ++ cloud-sql/postgres/sqlalchemy/app.py | 2 ++ cloud-sql/sql-server/sqlalchemy/app.py | 1 + 3 files changed, 5 insertions(+) diff --git a/cloud-sql/mysql/sqlalchemy/app.py b/cloud-sql/mysql/sqlalchemy/app.py index 6f65b20be322..016c5119a5e8 100644 --- a/cloud-sql/mysql/sqlalchemy/app.py +++ b/cloud-sql/mysql/sqlalchemy/app.py @@ -59,6 +59,7 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None: "( vote_id SERIAL NOT NULL, time_cast timestamp NOT NULL, " "candidate VARCHAR(6) NOT NULL, PRIMARY KEY (vote_id) );" )) + conn.commit() # This global variable is declared with a value of `None`, instead of calling @@ -139,6 +140,7 @@ def save_vote(db: sqlalchemy.engine.base.Engine, team: str) -> Response: # back into the pool at the end of statement (even if an error occurs) with db.connect() as conn: conn.execute(stmt, parameters={"time_cast": time_cast, "candidate": team}) + conn.commit() except Exception as e: # If something goes wrong, handle the error in this section. This might # involve retrying or adjusting parameters depending on the situation. diff --git a/cloud-sql/postgres/sqlalchemy/app.py b/cloud-sql/postgres/sqlalchemy/app.py index 624d7f21f954..670f14c16fe1 100644 --- a/cloud-sql/postgres/sqlalchemy/app.py +++ b/cloud-sql/postgres/sqlalchemy/app.py @@ -59,6 +59,7 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None: "( vote_id SERIAL NOT NULL, time_cast timestamp NOT NULL, " "candidate VARCHAR(6) NOT NULL, PRIMARY KEY (vote_id) );" )) + conn.commit() # This global variable is declared with a value of `None`, instead of calling @@ -139,6 +140,7 @@ def save_vote(db: sqlalchemy.engine.base.Engine, team: str) -> Response: # back into the pool at the end of statement (even if an error occurs) with db.connect() as conn: conn.execute(stmt, parameters={"time_cast": time_cast, "candidate": team}) + conn.commit() except Exception as e: # If something goes wrong, handle the error in this section. This might # involve retrying or adjusting parameters depending on the situation. diff --git a/cloud-sql/sql-server/sqlalchemy/app.py b/cloud-sql/sql-server/sqlalchemy/app.py index 3cbbb1b61fb5..2ee47284fcb0 100644 --- a/cloud-sql/sql-server/sqlalchemy/app.py +++ b/cloud-sql/sql-server/sqlalchemy/app.py @@ -137,6 +137,7 @@ def save_vote(db: sqlalchemy.engine.base.Engine, team: str) -> Response: # back into the pool at the end of statement (even if an error occurs) with db.connect() as conn: conn.execute(stmt, parameters={"time_cast": time_cast, "candidate": team}) + conn.commit() except Exception as e: # If something goes wrong, handle the error in this section. This might # involve retrying or adjusting parameters depending on the situation.