Skip to content

Undocumented breaking change in SFTPHook in airflow-providers-sftp 5.1.0 release #47129

Description

@agreenburg

Apache Airflow Provider(s)

sftp

Versions of Apache Airflow Providers

apache-airflow-providers-sftp 5.1.0

Apache Airflow version

2.10.4+astro.1

Operating System

Astronomer Runtime 12.6.0

Deployment

Astronomer

Deployment details

No response

What happened

We have python operator code that expects SFTPHook.get_conn() to return a paramiko.SFTPClient instance.

In 5.1.0 this code was changed to return Generator[SFTPClient] instead. This is causing this existing code to fail:

conn = sftpHook.get_conn()
conn.listdir_attr(remoteRootDir)

with this error:

AttributeError: '_GeneratorContextManager' object has no attribute 'listdir_attr'

Reverting to version 5.0.0 allows the code to run as before.

What you think should happen instead

Breaking changes should be documented in the changelog.

How to reproduce

conn = sftpHook.get_conn()
conn.listdir_attr(remoteRootDir)

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. vivek-meka commented on Feb 27, 2025

    @vivek-meka

    Yes here is the change that caused this issue. PR

    Looks like we have below options as of now based on how you are using SFTPHook

    • Use airflow-providers-sftp version 5.0.0
    • Change how we are using the SFTPHook
      Instead of this
      conn = sftpHook.get_conn()
      conn.listdir_attr(remoteRootDir)
    

    Use this

       with sftpHook.get_conn() as conn:
         conn.listdir_attr(remoteRootDir)
    
  2. dabla commented on Feb 28, 2025

    @dabla
    Contributor

    Created PR to address this issue.

  3. dabla commented on Feb 28, 2025

    @dabla
    Contributor

    with sftpHook.get_conn() as conn:
    conn.listdir_attr(remoteRootDir)

    Above would now become:

    with sftpHook.get_managed_conn() as conn:
          conn.listdir_attr(remoteRootDir)
    

    While get_conn wil return cached SFTPClient like original implementation:

    conn = sftpHook.get_conn()
    conn.listdir_attr(remoteRootDir)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions