This is an automated email from the ASF dual-hosted git repository. jedcunningham pushed a commit to branch v2-8-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 1651ee74bdb3ff37edaa05059346bc95f417c273 Author: Andrey Anshin <[email protected]> AuthorDate: Wed Jan 17 02:35:48 2024 +0400 REST API set description on POST to `/variables` endpoint (#36820) (cherry picked from commit 6d5d3555cbd22a3223e6fc14888442ad5b588e2e) --- airflow/api_connexion/endpoints/variable_endpoint.py | 3 +-- .../endpoints/test_variable_endpoint.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/airflow/api_connexion/endpoints/variable_endpoint.py b/airflow/api_connexion/endpoints/variable_endpoint.py index d7ee84c793..a59aa2f4c1 100644 --- a/airflow/api_connexion/endpoints/variable_endpoint.py +++ b/airflow/api_connexion/endpoints/variable_endpoint.py @@ -137,8 +137,7 @@ def post_variables() -> Response: """Create a variable.""" try: data = variable_schema.load(get_json_request_dict()) - except ValidationError as err: raise BadRequest("Invalid Variable schema", detail=str(err.messages)) - Variable.set(data["key"], data["val"]) + Variable.set(data["key"], data["val"], description=data.get("description", None)) return variable_schema.dump(data) diff --git a/tests/api_connexion/endpoints/test_variable_endpoint.py b/tests/api_connexion/endpoints/test_variable_endpoint.py index 3b75254774..ab9dddf454 100644 --- a/tests/api_connexion/endpoints/test_variable_endpoint.py +++ b/tests/api_connexion/endpoints/test_variable_endpoint.py @@ -335,13 +335,21 @@ class TestPatchVariable(TestVariableEndpoint): class TestPostVariables(TestVariableEndpoint): - def test_should_create_variable(self, session): + @pytest.mark.parametrize( + "description", + [ + pytest.param(None, id="not-set"), + pytest.param("", id="empty"), + pytest.param("Spam Egg", id="desc-set"), + ], + ) + def test_should_create_variable(self, description, session): + payload = {"key": "var_create", "value": "{}"} + if description is not None: + payload["description"] = description response = self.client.post( "/api/v1/variables", - json={ - "key": "var_create", - "value": "{}", - }, + json=payload, environ_overrides={"REMOTE_USER": "test"}, ) assert response.status_code == 200 @@ -350,7 +358,7 @@ class TestPostVariables(TestVariableEndpoint): assert response.json == { "key": "var_create", "value": "{}", - "description": None, + "description": description, } def test_should_reject_invalid_request(self, session):
