Skip to content

Commit

Permalink
[v2-10-test] Fix problem with inability to remove fields from Connect…
Browse files Browse the repository at this point in the history
…ion form (#40421) (#44442)

(cherry picked from commit 14bfe39)

Co-authored-by: Maksim <maksimy@google.com>
  • Loading branch information
github-actions[bot] and MaksYermak authored Nov 28, 2024
1 parent bed1aff commit 8185237
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4357,6 +4357,8 @@ def process_form(self, form, is_created):
# value isn't an empty string.
if value != "":
extra[field_name] = value
elif field_name in extra:
del extra[field_name]
if extra.keys():
sensitive_unchanged_keys = set()
for key, value in extra.items():
Expand Down
26 changes: 26 additions & 0 deletions tests/www/views/test_views_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,32 @@ def test_process_form_extras_updates_sensitive_placeholder_unchanged(
}


@mock.patch("airflow.utils.module_loading.import_string")
@mock.patch("airflow.providers_manager.ProvidersManager.hooks", new_callable=PropertyMock)
def test_process_form_extras_remove(mock_pm_hooks, mock_import_str):
"""
Test the remove value from field.
"""
# Testing parameters set in both extra and custom fields (connection updates).
mock_form = mock.Mock()
mock_form.data = {
"conn_type": "test4",
"conn_id": "extras_test4",
"extra": '{"extra__test4__remove_field": "remove_field_val3"}',
"extra__test4__remove_field": "",
}

cmv = ConnectionModelView()
cmv._iter_extra_field_names_and_sensitivity = mock.Mock(
return_value=[("extra__test4__remove_field", "remove_field", False)]
)
cmv.process_form(form=mock_form, is_created=True)

assert json.loads(mock_form.extra.data) == {
"extra__test4__remove_field": "remove_field_val3",
}


def test_duplicate_connection(admin_client):
"""Test Duplicate multiple connection with suffix"""
conn1 = Connection(
Expand Down

0 comments on commit 8185237

Please sign in to comment.