This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v2-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v2-10-test by this push:
new 8185237b85c [v2-10-test] Fix problem with inability to remove fields
from Connection form (#40421) (#44442)
8185237b85c is described below
commit 8185237b85c4fed9f7c1e98b8817cd293d59837c
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Nov 28 04:51:34 2024 +0100
[v2-10-test] Fix problem with inability to remove fields from Connection
form (#40421) (#44442)
(cherry picked from commit 14bfe39298a2361ae34eac840aebae84063306ee)
Co-authored-by: Maksim <[email protected]>
---
airflow/www/views.py | 2 ++
tests/www/views/test_views_connection.py | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 222759e6e67..92fa534f571 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -4357,6 +4357,8 @@ class ConnectionModelView(AirflowModelView):
# 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():
diff --git a/tests/www/views/test_views_connection.py
b/tests/www/views/test_views_connection.py
index a209cdfc2be..c70e6d19d48 100644
--- a/tests/www/views/test_views_connection.py
+++ b/tests/www/views/test_views_connection.py
@@ -316,6 +316,32 @@ def
test_process_form_extras_updates_sensitive_placeholder_unchanged(
}
[email protected]("airflow.utils.module_loading.import_string")
[email protected]("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(