Skip to content

SnowflakeHook reuses expired OAuth tokens for long-running tasks #60023

@SameerMesiah97

Description

@SameerMesiah97

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

  1. Create a Snowflake connection in Airflow using OAuth with the refresh_token grant type. The default Snowflake OAuth access token lifetime should be 10 mins.

  2. Add the following DAG, which reuses a single SnowflakeHook instance 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()
  1. Trigger the DAG and wait for the task to complete the sleep period.

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerskind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yetprovider:snowflakeIssues related to Snowflake provider

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions