-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Enable use of custom conn extra fields without prefix #22607
Enable use of custom conn extra fields without prefix #22607
Conversation
Needs rebase (FAB upgrade) |
8cb3a7e
to
6122689
Compare
ok done |
6122689
to
b008b3f
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. |
b008b3f
to
acf17ab
Compare
c8a98ee
to
400c4e7
Compare
@josh-fell mentioned some potential issues with this so converting to draft for now while i investigate |
Previously, connection "extra" fields which were added as custom fields in the webserver connection form had to be named with prefix `extra__<conn_type>__`. This was because custom fields are registered globally on the connection view model, so the prefix was necessary to prevent collisions. But the prefix is ugly and cumbersome in the `extra` field. So now what we do is add this prefix when defining the field internally in the model, and strip it when saving the connection.
Co-authored-by: Jed Cunningham <[email protected]>
Co-authored-by: Jed Cunningham <[email protected]>
400c4e7
to
5728a82
Compare
ok @josh-fell i think i came up with a reasonable solution to the "test connection" issue |
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.
LGTM!
Overview
Historically when adding custom extra fields we had to store them in the
extra
json field asextra__conn_type__field_name
.This was somewhat cumbersome. And it meant that when adding them as UI form fields, you had to make a change to the structure of the
extra
schema.With this PR, we do away with the requirement of this prefix. In effect, we separate the field "key" -- how it is identified internally in the model and form -- with "name", how it is identified in the
extra
json field.This leaves us with a backward compatible change, so that we can update hook classes (or class families) one at a time.
Notes on behavior
For hooks which have not updated
get_connection_form_widgets
to remove the prefixes, there's no change in behavior.But for hooks that have, then in the Web UI, when reading the connection (e.g. for an update) Airflow will check first for non-prefixed value then if it doesn't find it, it will check for prefixed value.
On save, it will always store in the manner defined by
get_connection_form_widgets
. In the case where theextra
field was defined pre-hook-upgrade, I leave the old (prefixed) value alone, so as to be non-destructive. However I can see an argument for removing the old vaule.When we update hooks to remove the prefix, we need to add a
_get_field
method to handle the extra lookup properly. Considering what happens with new hook and old airflow, we either have to bump min airflow version, or add Airflow-backcompat logic to re-prefix when using with an old version of Airflow. And I suppose this can be decided on a case-by-case basis with each provider.Other note
When implementing
get_ui_field_behaviour
for custom fields, you still will have to reference the prefixed field name. This I don't really like, but to solve it we'd have to do something a lot more elaborate and this is the simplest approach.