-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Add hook_params to SqlSensor.
#18431
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
Conversation
|
Hi, @SamWheating. |
airflow/models/connection.py
Outdated
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.
It is discouraged to pass a mutable object as a default. See this SO https://stackoverflow.com/q/1132941/621058 . Instead you can null it by default and if it's null assign it later
def get_hook(self, hook_params: Dict = None):
if hook_params is None:
hook_params = {}
# ...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.
Yeah, I've also had to deal with the problem described in SO.
But in this case, Dict is just a container and hasn't been updated in the method.
Could you please write an example in the context of SqlSensor when we can receive the behavior similar to SO?
Because now, in my opinion, it looks like code sophistication.
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 understand your point @kazanzhy but I agree we should just stick with the practice of using None as the default for Optional[Dict] that is, as far as I know, uniformly adhered to in this repo.
If you leave it, people will always give it a second look when they see it. And pycharm complains about it. And using None for an optional arg is also a common pattern that I think is good aside from the mutability issue, just sends the message, you don't need to pass this, and we don't forward anything in this case.
|
Hello there. Been on holiday for some time, thats why #17592 was stalled. I see you get good progress here, including adding the missing DbHooks. Tell me If I can contribute somehow, just don't want to duplicate efforts |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
dstandish
left a comment
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 think this needs to be split into 2 prs. This one should only add hook_params. Changing the conn types should be done separately.
airflow/models/connection.py
Outdated
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 understand your point @kazanzhy but I agree we should just stick with the practice of using None as the default for Optional[Dict] that is, as far as I know, uniformly adhered to in this repo.
If you leave it, people will always give it a second look when they see it. And pycharm complains about it. And using None for an optional arg is also a common pattern that I think is good aside from the mutability issue, just sends the message, you don't need to pass this, and we don't forward anything in this case.
airflow/sensors/sql.py
Outdated
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.
same as above
ec1586c to
bb3ac65
Compare
hook_kwargs and fix allowed_conn_types for SqlSensor.
hook_kwargs and fix allowed_conn_types for SqlSensor.hook_params and fix allowed_conn_types for SqlSensor.
ca1e4f9 to
14562be
Compare
|
I updated the description. Also changed name of the parameter to |
hook_params and fix allowed_conn_types for SqlSensor.hook_params to SqlSensor.
459a652 to
f7abbfc
Compare
|
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
f7abbfc to
a2fa615
Compare
a2fa615 to
648254d
Compare
|
Awesome work, congrats on your first merged pull request! |
This PR is based on: #17592 and closes: #13750
SqlSensor relies on underlying hooks that are automatically injected (DI) depending on the connection type provided to the SqlSensor. However, from time to time (but mainly in BigqueryHook) it is needed to pre-configure the "to-be-injected" hook because some default params do not fit the current config.
For example, if using SqlSensor with Bigquery it by default configures the SQL dialect to "legacy SQL", and there is no way to change this through configuration. Instead, the SqlSensor has to be extended and some functions are overwritten.