@@ -100,7 +100,7 @@ def connect(dbapi_connection, connection_record):
100100 self ._logger .disabled = True
101101 try :
102102 connection = self ._engine .connect ()
103- connection .execute ("SELECT 1" )
103+ connection .execute (sqlalchemy . text ( "SELECT 1" ) )
104104 connection .close ()
105105 except sqlalchemy .exc .OperationalError as e :
106106 e = RuntimeError (_parse_exception (e ))
@@ -153,10 +153,10 @@ def execute(self, sql, *args, **kwargs):
153153 full_statement = ' ' .join (str (token ) for token in statements [0 ].tokens if token .ttype in [sqlparse .tokens .Keyword , sqlparse .tokens .Keyword .DDL , sqlparse .tokens .Keyword .DML ])
154154 full_statement = full_statement .upper ()
155155
156- # set of possible commands
156+ # Set of possible commands
157157 commands = {"BEGIN" , "CREATE VIEW" , "DELETE" , "INSERT" , "SELECT" , "START" , "UPDATE" }
158158
159- # check if the full_statement starts with any command
159+ # Check if the full_statement starts with any command
160160 command = next ((cmd for cmd in commands if full_statement .startswith (cmd )), None )
161161
162162 # Flatten statement
@@ -344,7 +344,7 @@ def teardown_appcontext(exception):
344344 if command == "SELECT" :
345345
346346 # Coerce types
347- rows = [dict (row ) for row in result .fetchall ()]
347+ rows = [dict (row ) for row in result .mappings (). all ()]
348348 for row in rows :
349349 for column in row :
350350
@@ -370,7 +370,7 @@ def teardown_appcontext(exception):
370370 # "(psycopg2.errors.ObjectNotInPrerequisiteState) lastval is not yet defined in this session",
371371 # a la https://stackoverflow.com/a/24186770/5156190;
372372 # cf. https://www.psycopg.org/docs/errors.html re 55000
373- result = connection .execute ("""
373+ result = connection .execute (sqlalchemy . text ( """
374374 CREATE OR REPLACE FUNCTION _LASTVAL()
375375 RETURNS integer LANGUAGE plpgsql
376376 AS $$
@@ -382,7 +382,7 @@ def teardown_appcontext(exception):
382382 END;
383383 END $$;
384384 SELECT _LASTVAL();
385- """ )
385+ """ ))
386386 ret = result .first ()[0 ]
387387
388388 # If not PostgreSQL
0 commit comments