Skip to content
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

Merged
merged 13 commits into from
Apr 25, 2022

Conversation

dstandish
Copy link
Contributor

@dstandish dstandish commented Mar 29, 2022

Overview

Historically when adding custom extra fields we had to store them in the extra json field as extra__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 the extra 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.

@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label Mar 29, 2022
@dstandish dstandish requested review from potiuk and josh-fell March 29, 2022 22:01
@potiuk
Copy link
Member

potiuk commented Apr 4, 2022

Needs rebase (FAB upgrade)

@dstandish dstandish force-pushed the deprecate-conn-extra-prefix branch from 8cb3a7e to 6122689 Compare April 4, 2022 16:49
@dstandish
Copy link
Contributor Author

Needs rebase (FAB upgrade)

ok done

@dstandish dstandish force-pushed the deprecate-conn-extra-prefix branch from 6122689 to b008b3f Compare April 15, 2022 15:51
@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Apr 20, 2022
@github-actions
Copy link

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.

@dstandish dstandish force-pushed the deprecate-conn-extra-prefix branch from b008b3f to acf17ab Compare April 22, 2022 13:47
newsfragments/22607.significant.rst Outdated Show resolved Hide resolved
newsfragments/22607.significant.rst Outdated Show resolved Hide resolved
tests/core/test_providers_manager.py Outdated Show resolved Hide resolved
tests/core/test_providers_manager.py Outdated Show resolved Hide resolved
tests/www/views/test_views_connection.py Outdated Show resolved Hide resolved
tests/www/views/test_views_connection.py Outdated Show resolved Hide resolved
tests/www/views/test_views_connection.py Outdated Show resolved Hide resolved
tests/www/views/test_views_connection.py Outdated Show resolved Hide resolved
tests/www/views/test_views_connection.py Outdated Show resolved Hide resolved
@dstandish dstandish force-pushed the deprecate-conn-extra-prefix branch from c8a98ee to 400c4e7 Compare April 22, 2022 21:58
@dstandish dstandish marked this pull request as draft April 25, 2022 12:03
@dstandish
Copy link
Contributor Author

@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.
@dstandish dstandish force-pushed the deprecate-conn-extra-prefix branch from 400c4e7 to 5728a82 Compare April 25, 2022 12:33
@dstandish dstandish marked this pull request as ready for review April 25, 2022 19:03
@dstandish
Copy link
Contributor Author

ok @josh-fell i think i came up with a reasonable solution to the "test connection" issue

Copy link
Contributor

@josh-fell josh-fell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dstandish dstandish merged commit 1dfae80 into apache:main Apr 25, 2022
@dstandish dstandish deleted the deprecate-conn-extra-prefix branch April 25, 2022 22:06
@jedcunningham jedcunningham added the type:improvement Changelog: Improvements label Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues full tests needed We need to run full set of tests for this PR to merge type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants