hubert-pietron commented on issue #16295:
URL: https://github.com/apache/airflow/issues/16295#issuecomment-1013711612
Need some advice.
I think it's caused because in jaydebeapi exceptions are firstly internally
handled and then reraised (And somehow task can't see that).
I found way to get Exception by rewriting _run_command from
airflow/hooks/dbapi.py in airflow/providers/jdbc/hooks/jdbc.py, and it would
look like this:
```
def _run_command(self, cur, sql_statement, parameters):
"""Runs a statement using an already open jaydebeapi cursor."""
self.log.info("Running statement: %s, parameters: %s",
sql_statement, parameters)
try:
if parameters:
cur.execute(sql_statement, parameters)
else:
cur.execute(sql_statement)
except (jaydebeapi.DatabaseError, jaydebeapi.InterfaceError) as e:
self.log.error(e)
raise
# According to PEP 249, this is -1 when query result is not
applicable.
if cur.rowcount >= 0:
self.log.info("Rows affected: %s", cur.rowcount)
```
Example log after change:
```
[2022-01-15, 16:02:49 UTC] {base.py:70} INFO - Using connection to: id:
jdbc_test. Host: jdbc:postgresql://172.19.0.1:25433/***, Port: None, Schema: ,
Login: postgres, Password: ***, extra: {'extra__jdbc__drv_clsname':
'org.postgresql.Driver', 'extra__jdbc__drv_path':
'/opt/***/postgresql-42.2.24.jre6.jar'}
[2022-01-15, 16:02:49 UTC] {jdbc.py:106} INFO - Running statement: select 1
from x , parameters: None
[2022-01-15, 16:02:49 UTC] {jdbc.py:113} ERROR -
org.postgresql.util.PSQLException: ERROR: relation "x" does not exist
Position: 15
[2022-01-15, 16:02:49 UTC] {local_task_job.py:153} INFO - Task exited with
return code 1
```
Please let me know if it's okay.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]