Skip to content

Commit 7c183c0

Browse files
fix(cloudsql): make connections commit as you go (GoogleCloudPlatform#9160)
1 parent 2c19974 commit 7c183c0

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

cloud-sql/mysql/sqlalchemy/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
5959
"( vote_id SERIAL NOT NULL, time_cast timestamp NOT NULL, "
6060
"candidate VARCHAR(6) NOT NULL, PRIMARY KEY (vote_id) );"
6161
))
62+
conn.commit()
6263

6364

6465
# 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:
139140
# back into the pool at the end of statement (even if an error occurs)
140141
with db.connect() as conn:
141142
conn.execute(stmt, parameters={"time_cast": time_cast, "candidate": team})
143+
conn.commit()
142144
except Exception as e:
143145
# If something goes wrong, handle the error in this section. This might
144146
# involve retrying or adjusting parameters depending on the situation.

cloud-sql/postgres/sqlalchemy/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
5959
"( vote_id SERIAL NOT NULL, time_cast timestamp NOT NULL, "
6060
"candidate VARCHAR(6) NOT NULL, PRIMARY KEY (vote_id) );"
6161
))
62+
conn.commit()
6263

6364

6465
# 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:
139140
# back into the pool at the end of statement (even if an error occurs)
140141
with db.connect() as conn:
141142
conn.execute(stmt, parameters={"time_cast": time_cast, "candidate": team})
143+
conn.commit()
142144
except Exception as e:
143145
# If something goes wrong, handle the error in this section. This might
144146
# involve retrying or adjusting parameters depending on the situation.

cloud-sql/sql-server/sqlalchemy/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def save_vote(db: sqlalchemy.engine.base.Engine, team: str) -> Response:
137137
# back into the pool at the end of statement (even if an error occurs)
138138
with db.connect() as conn:
139139
conn.execute(stmt, parameters={"time_cast": time_cast, "candidate": team})
140+
conn.commit()
140141
except Exception as e:
141142
# If something goes wrong, handle the error in this section. This might
142143
# involve retrying or adjusting parameters depending on the situation.

0 commit comments

Comments
 (0)