Skip to content

Commit dac2ae8

Browse files
committed
Stylistic changes.
1 parent c60d67d commit dac2ae8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/cs50/sql.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def execute(self, sql, *args, **kwargs):
135135
elif token.value.upper() in ["BEGIN", "START"]:
136136
if self._in_transaction:
137137
raise RuntimeError("transaction already open")
138+
138139
self._in_transaction = True
139140
else:
140141
command = None
@@ -296,8 +297,8 @@ def execute(self, sql, *args, **kwargs):
296297
assert flask.current_app
297298

298299
# Disconnect later - but only once
299-
if not hasattr(self, "teardown_appcontext_added"):
300-
self.teardown_appcontext_added = True
300+
if not hasattr(self, "_teardown_appcontext_added"):
301+
self._teardown_appcontext_added = True
301302

302303
@flask.current_app.teardown_appcontext
303304
def shutdown_session(exception=None):
@@ -320,9 +321,10 @@ def shutdown_session(exception=None):
320321
_statement = "".join([str(bytes) if token.ttype == sqlparse.tokens.Other else str(token) for token in tokens])
321322

322323
# If COMMIT or ROLLBACK, turn on autocommit mode
323-
if command in ["COMMIT", "ROLLBACK"] and "TO" not in statement:
324+
if command in ["COMMIT", "ROLLBACK"] and "TO" not in (token.value for token in tokens):
324325
if not self._in_transaction:
325326
raise RuntimeError("transactions must be initiated with BEGIN or START TRANSACTION")
327+
326328
self._in_transaction = False
327329

328330
# Execute statement
@@ -393,6 +395,7 @@ def _close_session(self):
393395
"""Closes any existing session and resets instance variables."""
394396
if self._session is not None:
395397
self._session.close()
398+
396399
self._session = None
397400
self._in_transaction = False
398401

0 commit comments

Comments
 (0)