Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/cs50/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ def shutdown_session(exception=None):
try:
result = connection.execute("SELECT LASTVAL()")
ret = result.first()[0]

# Commit changes to Postgres
connection.execute("COMMIT")

except sqlalchemy.exc.OperationalError: # If lastval is not yet defined in this session
ret = None
else:
Expand All @@ -356,6 +360,9 @@ def shutdown_session(exception=None):
# If DELETE or UPDATE, return number of rows matched
elif command in ["DELETE", "UPDATE"]:
ret = result.rowcount
# Commit changes to Postgres
if self._engine.url.get_backend_name() in ["postgres", "postgresql"]:
connection.execute("COMMIT")

# If constraint violated, return None
except sqlalchemy.exc.IntegrityError as e:
Expand Down