diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py index 744dff444fd3e..5492487377048 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py @@ -203,8 +203,12 @@ def patch_connection( status.HTTP_404_NOT_FOUND, f"The Connection with connection_id: `{connection_id}` was not found" ) + fields_to_update = patch_body.model_fields_set + if update_mask: + fields_to_update = fields_to_update.intersection(update_mask) + try: - ConnectionBody(**patch_body.model_dump()) + ConnectionBody(**patch_body.model_dump(include=fields_to_update)) except ValidationError as e: raise RequestValidationError(errors=e.errors()) diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py index f4c9186cd2fca..cec2d7ca9a5d9 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py @@ -286,11 +286,11 @@ def patch_dag( status.HTTP_400_BAD_REQUEST, "Only `is_paused` field can be updated through the REST API" ) fields_to_update = fields_to_update.intersection(update_mask) - else: - try: - DAGPatchBody(**patch_body.model_dump()) - except ValidationError as e: - raise RequestValidationError(errors=e.errors()) + + try: + DAGPatchBody(**patch_body.model_dump(include=fields_to_update)) + except ValidationError as e: + raise RequestValidationError(errors=e.errors()) data = patch_body.model_dump(include=fields_to_update, by_alias=True) diff --git a/airflow-core/src/airflow/api_fastapi/core_api/services/public/variables.py b/airflow-core/src/airflow/api_fastapi/core_api/services/public/variables.py index a5011768cb0aa..e7a05567bb451 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/services/public/variables.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/services/public/variables.py @@ -65,11 +65,15 @@ def update_orm_from_pydantic( status.HTTP_404_NOT_FOUND, f"The Variable with key: `{variable_key}` was not found" ) + non_update_fields = {"key"} + fields_to_update = patch_body.model_fields_set + if update_mask: + fields_to_update = fields_to_update.intersection(update_mask) + try: - VariableBody(**patch_body.model_dump()) + VariableBody(**patch_body.model_dump(include=fields_to_update)) except ValidationError as e: raise RequestValidationError(errors=e.errors()) - non_update_fields = {"key"} if patch_body.key != old_variable.key: raise HTTPException(