-
Notifications
You must be signed in to change notification settings - Fork 16.2k
Description
Apache Airflow Provider(s)
snowflake
Versions of Apache Airflow Providers
apache-airflow-providers-snowflake==6.8.1rc1
Apache Airflow version
3.1.5 & main
Operating System
Debian GNU/Linux 12 (bookworm)
Deployment
Other
Deployment details
No response
What happened
When using SnowflakeHook with OAuth authentication, long-running tasks that reuse the same hook instance fail after the OAuth access token expires. The hook continues to reuse an expired token because it is resolved as part of cached connection parameters, preventing the refresh logic from being re-evaluated. As a result, subsequent Snowflake operations fail with an invalid or expired access token error.
What you think should happen instead
SnowflakeHook should re-evaluate OAuth token validity whenever connection parameters are resolved and refresh the token automatically if it has expired. Long-running tasks that reuse the same hook instance should continue to operate successfully without authentication errors, while static connection parameters remain cached and unchanged.
How to reproduce
-
Create a Snowflake connection in Airflow using OAuth with the
refresh_tokengrant type. The default Snowflake OAuth access token lifetime should be 10 mins. -
Add the following DAG, which reuses a single
SnowflakeHookinstance across multiple operations:
from datetime import datetime
import time
from airflow.decorators import dag, task
from airflow.providers.snowflake.hooks.snowflake import SnowflakeHook
@task
def long_running_snowflake_task():
hook = SnowflakeHook(snowflake_conn_id=[Connection ID])
hook.run("SELECT 1")
# Sleep longer than the default OAuth token lifetime (10 minutes)
time.sleep(11 * 60)
hook.run("SELECT 1")
@dag(start_date=datetime(2025, 12, 1))
def snowflake_oauth_expiry_repro():
long_running_snowflake_task()
dag = snowflake_oauth_expiry_repro()
-
Trigger the DAG and wait for the task to complete the sleep period.
-
The DAG should fail and you should see the following error messsage in the task execution logs for
long_running_snowflake_task:
DatabaseError: 250001 (08001): Failed to connect to DB:
<account>.snowflakecomputing.com:443.
OAuth access token expired. [error code redacted]
Anything else
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct