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 74b0fd98f98 Use default max depth to redact Variable (#63480)
74b0fd98f98 is described below

commit 74b0fd98f9876374c52a2d4acd891497c3b93774
Author: Kevin Yang <[email protected]>
AuthorDate: Fri Mar 13 06:52:49 2026 -0400

    Use default max depth to redact Variable (#63480)
    
    * use default max depth for variable redact
    
    * update test cases
---
 .../api_fastapi/core_api/datamodels/variables.py   |  2 +-
 .../core_api/routes/public/test_variables.py       | 47 +++++++++++++++++-----
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py 
b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py
index f952a5a7770..9dc7969b69b 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py
@@ -43,7 +43,7 @@ class VariableResponse(BaseModel):
             return self
         try:
             val_dict = json.loads(self.val)
-            redacted_dict = redact(val_dict, max_depth=1)
+            redacted_dict = redact(val_dict)
             self.val = json.dumps(redacted_dict)
             return self
         except json.JSONDecodeError:
diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_variables.py 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_variables.py
index 467b03554f0..50871879675 100644
--- 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_variables.py
+++ 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_variables.py
@@ -49,6 +49,10 @@ TEST_VARIABLE_KEY3 = "dictionary_password"
 TEST_VARIABLE_VALUE3 = '{"password": "some_password"}'
 TEST_VARIABLE_DESCRIPTION3 = "Some description for the variable"
 
+TEST_VARIABLE_KEY5 = "nested_dictionary_variable"
+TEST_VARIABLE_VALUE5 = '{"config": {"password": "some_password", "next": 
{"api_key": "some_api_key", "next_again": {"token": "some_token"}}}}'
+TEST_VARIABLE_DESCRIPTION5 = "Variable with a nested sensitive key"
+
 TEST_VARIABLE_KEY4 = "test_variable_key/with_slashes"
 TEST_VARIABLE_VALUE4 = "test_variable_value"
 TEST_VARIABLE_DESCRIPTION4 = "Some description for the variable"
@@ -104,6 +108,13 @@ def _create_variables(session) -> None:
         session=session,
     )
 
+    Variable.set(
+        key=TEST_VARIABLE_KEY5,
+        value=TEST_VARIABLE_VALUE5,
+        description=TEST_VARIABLE_DESCRIPTION5,
+        session=session,
+    )
+
 
 @provide_session
 def _create_team(session) -> None:
@@ -132,13 +143,13 @@ class TestDeleteVariable(TestVariableEndpoint):
     def test_delete_should_respond_204(self, test_client, session):
         self.create_variables()
         variables = session.scalars(select(Variable)).all()
-        assert len(variables) == 5
+        assert len(variables) == 6
         response = test_client.delete(f"/variables/{TEST_VARIABLE_KEY}")
         assert response.status_code == 204
         response = test_client.delete(f"/variables/{TEST_VARIABLE_KEY4}")
         assert response.status_code == 204
         variables = session.scalars(select(Variable)).all()
-        assert len(variables) == 3
+        assert len(variables) == 4
         check_last_log(session, dag_id=None, event="delete_variable", 
logical_date=None)
 
     def test_delete_should_respond_401(self, unauthenticated_test_client):
@@ -211,6 +222,16 @@ class TestGetVariable(TestVariableEndpoint):
                     "team_name": None,
                 },
             ),
+            (
+                TEST_VARIABLE_KEY5,
+                {
+                    "key": TEST_VARIABLE_KEY5,
+                    "value": '{"config": {"password": "***", "next": 
{"api_key": "***", "next_again": {"token": "***"}}}}',
+                    "description": TEST_VARIABLE_DESCRIPTION5,
+                    "is_encrypted": True,
+                    "team_name": None,
+                },
+            ),
         ],
     )
     def test_get_should_respond_200(self, test_client, session, key, 
expected_response):
@@ -242,33 +263,36 @@ class TestGetVariables(TestVariableEndpoint):
             # Filters
             (
                 {},
-                5,
+                6,
                 [
                     TEST_VARIABLE_KEY,
                     TEST_VARIABLE_KEY2,
                     TEST_VARIABLE_KEY3,
                     TEST_VARIABLE_KEY4,
                     TEST_VARIABLE_SEARCH_KEY,
+                    TEST_VARIABLE_KEY5,
                 ],
             ),
-            ({"limit": 1}, 5, [TEST_VARIABLE_KEY]),
-            ({"limit": 1, "offset": 1}, 5, [TEST_VARIABLE_KEY2]),
+            ({"limit": 1}, 6, [TEST_VARIABLE_KEY]),
+            ({"limit": 1, "offset": 1}, 6, [TEST_VARIABLE_KEY2]),
             # Sort
             (
                 {"order_by": "id"},
-                5,
+                6,
                 [
                     TEST_VARIABLE_KEY,
                     TEST_VARIABLE_KEY2,
                     TEST_VARIABLE_KEY3,
                     TEST_VARIABLE_KEY4,
                     TEST_VARIABLE_SEARCH_KEY,
+                    TEST_VARIABLE_KEY5,
                 ],
             ),
             (
                 {"order_by": "-id"},
-                5,
+                6,
                 [
+                    TEST_VARIABLE_KEY5,
                     TEST_VARIABLE_SEARCH_KEY,
                     TEST_VARIABLE_KEY4,
                     TEST_VARIABLE_KEY3,
@@ -278,9 +302,10 @@ class TestGetVariables(TestVariableEndpoint):
             ),
             (
                 {"order_by": "key"},
-                5,
+                6,
                 [
                     TEST_VARIABLE_KEY3,
+                    TEST_VARIABLE_KEY5,
                     TEST_VARIABLE_KEY2,
                     TEST_VARIABLE_KEY,
                     TEST_VARIABLE_KEY4,
@@ -289,25 +314,27 @@ class TestGetVariables(TestVariableEndpoint):
             ),
             (
                 {"order_by": "-key"},
-                5,
+                6,
                 [
                     TEST_VARIABLE_SEARCH_KEY,
                     TEST_VARIABLE_KEY4,
                     TEST_VARIABLE_KEY,
                     TEST_VARIABLE_KEY2,
+                    TEST_VARIABLE_KEY5,
                     TEST_VARIABLE_KEY3,
                 ],
             ),
             # Search
             (
                 {"variable_key_pattern": "~"},
-                5,
+                6,
                 [
                     TEST_VARIABLE_KEY,
                     TEST_VARIABLE_KEY2,
                     TEST_VARIABLE_KEY3,
                     TEST_VARIABLE_KEY4,
                     TEST_VARIABLE_SEARCH_KEY,
+                    TEST_VARIABLE_KEY5,
                 ],
             ),
             ({"variable_key_pattern": "search"}, 1, 
[TEST_VARIABLE_SEARCH_KEY]),

Reply via email to