Skip to content

Conversation

@dabla
Copy link
Contributor

@dabla dabla commented Feb 28, 2025

closes: #47129
closes: #47201


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

…tead of context manager for backward compatibility
…egated method use the context manager which take care of closing the connection
@potiuk
Copy link
Member

potiuk commented Feb 28, 2025

nice! thanks!

@dabla
Copy link
Contributor Author

dabla commented Feb 28, 2025

I've called the context managed connection get_sftp_conn, but I'm not happy with that name so I asked ChatGPT what would be an appropriate name for the context managed connection method:

Option 1: connect()

✅ Simple and intuitive
✅ Follows naming conventions in some database libraries (e.g., SQLAlchemy's connect())

Option 2: get_managed_conn()

✅ Clearly indicates that it manages the connection lifecycle
✅ Works well if other hook classes have a similar pattern

Option 3: use_conn()

✅ Short and easy to read
✅ "Use" implies temporary access, aligning with a context manager

What do you guys think? I would tend to choose option 2 or 3, as 3 could already be used I think and is confusing in my opinion.

@potiuk
Copy link
Member

potiuk commented Feb 28, 2025

2 is good

@potiuk potiuk merged commit c51010f into apache:main Feb 28, 2025
60 checks passed
nailo2c pushed a commit to nailo2c/airflow that referenced this pull request Apr 4, 2025
… SFTPClient instead of context managed connection (apache#47217)

* fix: SFTPHook.get_conn method should return SFTPClient connection instead of context manager for backward compatibility

* fix: SFTPSensor doesn't need to call the close_conn method as the delegated method use the context manager which take care of closing the connection

* refactor: Make sure SFTPSensor doesn't need to call the close_conn method anymore and test this behaviour

* refactor: Renamed get_sftp_conn method of SFTPHook to use_conn

* refactor: Renamed use_conn method of SFTPHook to get_managed_conn

---------

Co-authored-by: David Blain <david.blain@infrabel.be>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'SFTPHook' object has no attribute 'close_conn' Undocumented breaking change in SFTPHook in airflow-providers-sftp 5.1.0 release

4 participants