-
Notifications
You must be signed in to change notification settings - Fork 80
Description
Driver version
redshift-connector 2.0.917
Redshift version
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.61626�
Client Operating System
Linux cc7c404a8a4d 6.5.11-linuxkit #1 SMP PREEMPT Wed Dec 6 17:08:31 UTC 2023 x86_64 GNU/Linux
Python version
3.11.7
Table schema
Problem description
When a SQL error occurs the warning 'UserWarning: DB-API extension cursor.connection used self._run_cursor.execute(sql, params, stream=stream)' is logged.
Catching the raised exception does not suppress the warning
Python Driver trace logs
Reproduction code
import redshift_connector
from getpass import getpass
from pprint import pprint as pp
host = 'the-host'
database = 'the-db'
user = 'the-user'
password = getpass('''What's the magic word! : ''')
def run_sql(*, conn, sql):
pp(sql)
rtn = None
try:
rtn = conn.run(sql)
except Exception as e:
pp(str(e))
conn.rollback()
return rtn
conn = redshift_connector.connect(host=host, database=database, user=user, password=password)
sql_list = [
'''select 'I`m a teapot' ''',
'''respond 'You`re a teapot' ''', # invalid sql of your choice
'''select 'Who`s a teapot' ''',
'''respond 'You`re a teapot' '''
]
res = [run_sql(conn=conn, sql=sql) for sql in sql_list]
pp(res)
Output
What's the magic word! :
"select 'Im a teapot' " "respond 'You
re a teapot' "
/home/vscode/.local/lib/python3.11/site-packages/redshift_connector/core.py:1321: UserWarning: DB-API extension cursor.connection used
self._run_cursor.execute(sql, params, stream=stream)
("{'S': 'ERROR', 'C': '42601', 'M': 'syntax error at or near "
'"respond"', 'P': '1', 'F': '
"'/home/ec2-user/padb/src/pg/src/backend/parser/parser_scan.l', 'L': '840', "
"'R': 'yyerror'}")
"select 'Whos a teapot' " "respond'You
re a teapot' "
("{'S': 'ERROR', 'C': '42601', 'M': 'syntax error at or near "
'"respond"', 'P': '1', 'F': '
"'/home/ec2-user/padb/src/pg/src/backend/parser/parser_scan.l', 'L': '840', "
"'R': 'yyerror'}")
[(['Im a teapot'],), None, (['Who
s a teapot'],), None]