This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 14bfe39298a Fix problem with inability to remove fields from 
Connection form (#40421)
14bfe39298a is described below

commit 14bfe39298a2361ae34eac840aebae84063306ee
Author: Maksim <[email protected]>
AuthorDate: Wed Nov 27 19:11:58 2024 -0800

    Fix problem with inability to remove fields from Connection form (#40421)
---
 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 35cfa45a85a..57f7b3c204f 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -4219,6 +4219,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 b588a56128e..28ea56a337a 100644
--- a/tests/www/views/test_views_connection.py
+++ b/tests/www/views/test_views_connection.py
@@ -321,6 +321,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(

Reply via email to