-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Refactoring connection in httphook #53407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
kyungjunleeme
wants to merge
3
commits into
apache:main
from
kyungjunleeme:refactor/get_conn_httphook
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love this approach. The previous syntax is the standard for almost all provider hooks. I don't think this change should be made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at first, Thanks ur commeting about my pr. :)
I recently worked on this PR, and I believe the same approach could be applied more broadly.
I'd like to take a bit more time to think it through, and then I'll request your review again. I think there's value in discussing it together to identify meaningful improvements.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to gradually refactor providers that currently follow this pattern:
To support this, I've added the following method in BaseHook:
Hardcoding the connection ID attribute directly can become a maintenance burden, especially as new providers are introduced. Using a consistent, dynamic approach like get_conn_id() makes the codebase more extensible and reduces the risk of subtle bugs. I believe this change will make future development and maintenance smoother.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to this change. I do not understand why the hard coded
<type>_conn_idwas actually made and what the benefit of this is/was. I assume this is still from times of Python 2.x and is coming from Airflow 1.x-times. But this was from the past/legacy before I joined the project.So would be cool asking some other committer with more history knowing a reason why the current construct exists. I hope there is a reason behind and not just a strange field design.
@potiuk @ashb @kaxil Do you know somebody from that point of history knowing the reason behind this design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why we have
xxx_conn_idisdefault_args.The pattern is that you can specify one
aws_conn_idin default_args and onegoogle_conn_idand then all AWS operators in the Dag would use the former and all Google operators would use the latter. So it makes perfect sense to use it and continue using it in the future - this reason still "stands" - so we should keep having that approach - i.e. generally samexxx_conn_idper provider should bestandardand we should keep it.And
conn_attr_nameis defined so that Connection.get_hook() used in a number of places - for example intest_connectioncan properly pass the conn_id to the right__init__parameter when it tries to instantiate the Hook dynamically.And I am not sure if we want to add get_conn_id() in BaseHook. It does not bring a lot of value IMHO. With autocomplete in IDE, MyPy and ruff checks, i pretty much like the explicit using of self.xxx_conn_id rather than get_conn_id(). I am not sure if there are real benefits of having it for all hooks. The real benefit would be to get rid of
conn_attr_nameand finding thexxx_conn_idautomaticaly - because that is where we have some level of duplication - same parameter name and "conn_attr_name" string.The only reason we used
get_conn_id()pattern so far was I think common.sql where it isactuallyneeded - if you look at DbApiHook, it has this implementation:And it is needed, because all SQL operators that take DbApiHook-derived Hooks are using get_conn_id to actually retrieve the connection id in consistent way. But this is really a
DbApiHookAPI rather than "BaseHook" API - and I am afraid moving it to BaseHook will muddy the waters and dillute that strong tie betweenDBApiHookandget_conn_id().Also in general - we should be VERY careful about modifying
Baseclasses from task.sdk. Those "task.sdk" classes are Public APIs of Airflow. I think basically anything we add there should go through discussion on devlist with justifying why we want to do it - because adding anything there will mean we will have to maintain it forever, and it will be extremely painful if we make some mistake there and release airflow with some changes that could make things difficult to maintain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the details. Did not consider the
default_args- in this light it makes perfectly sense.