sushi30 opened a new issue #20633:
URL: https://github.com/apache/airflow/issues/20633


   ### Apache Airflow Provider(s)
   
   trino
   
   ### Versions of Apache Airflow Providers
   
   Due to https://github.com/trinodb/trino-python-client/issues/95, trino hook 
does not capture error when using the `run` command.
   
   ### Apache Airflow version
   
   2.2.2
   
   ### Operating System
   
   Centos 7
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   _No response_
   
   ### What happened
   
   _No response_
   
   ### What you expected to happen
   
   Trino hook should fail when query fails.
   
   ### How to reproduce
   
   Just use the trino hook with a nonsense query like:
   
   ```sql
   select aaaaa
   ```
   
   ### Anything else
   
   As a workaround I implemented this custom hook:
   
   ```python
   from airflow.providers.trino.hooks.trino import TrinoHook as BaseTrinoHook
   class TrinoHook(BaseTrinoHook):
       def run(self, hql, autocommit: bool = False, parameters: Optional[dict] 
= None) -> None:
           """Due to issue 
https://github.com/trinodb/trino-python-client/issues/95 trino-python-client 
does not
           capture errors unless using fetchall. This hook is a workaround 
until this is fixed."""
           sql = [hql] if isinstance(hql, str) else hql
           sql = [self._strip_sql(s) for s in sql]
           with closing(self.get_conn()) as conn:
               if self.supports_autocommit:
                   self.set_autocommit(conn, autocommit)
               with closing(conn.cursor()) as cur:
                   for sql_statement in sql:
                       self._run_command(cur, sql_statement, parameters)
                   cur.fetchone()
   ```
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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]


Reply via email to