[go: up one dir, main page]

Skip to content

Commit

Permalink
fix(cloudsql): make connections commit as you go (#9160)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon committed Feb 22, 2023
1 parent 2c19974 commit 7c183c0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cloud-sql/mysql/sqlalchemy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions cloud-sql/postgres/sqlalchemy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cloud-sql/sql-server/sqlalchemy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7c183c0

Please sign in to comment.