taylor-paskett commented on issue #58724:
URL: https://github.com/apache/airflow/issues/58724#issuecomment-3825024252
I am also able to re-create this issue in airflow 3.1.6 when trying to use a
`SnowflakeHook` in a PythonVirtualenvOperator, which fails because the Task SDK
can't access the Connection. Here's an example of a monkey patch I've
successfully used to fix the Snowflake hook. It could potentially be modified
for whichever hook you're having a problem with.
```python
import os
from airflow.providers.snowflake.hooks.snowflake import SnowflakeHook
from airflow.sdk import Connection
def function_that_uses_snowflake(snowflake_conn_id):
SnowflakeHook.get_connection = lambda _, conn_id: Connection.from_uri(
os.environ.get(f"AIRFLOW_CONN_{conn_id.upper()}", ""), conn_id
)
snowflake_hook = SnowflakeHook(snowflake_conn_id)
return snowflake_hook.get_pandas_df("SELECT * FROM my_table")
```
This assumes that you are supplying the connection through the environment,
and not e.g. through the Airflow Web UI. The main bit is manually using the
`Connection.from_uri` when you're in a PythonVirtualenvOperator.
This monkey patch is just a temporary workaround. I was not able to find out
the root cause; it would help to be more familiar with Airflow's codebase.
--
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]