Vamsi-klu commented on code in PR #62657:
URL: https://github.com/apache/airflow/pull/62657#discussion_r2899070912


##########
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))

Review Comment:
   Thanks for the review! You were right — validating partial data against the 
full `ConnectionBody` model fails because of required fields like 
`connection_id` and `conn_type`.
   
   Per @pierrejeambrun's suggestion, I've now implemented this with partial 
Pydantic models:
   
   - Added a `make_partial_model()` helper in `base.py` that creates a subclass 
with all fields `Optional` (default `None`), while preserving validators, 
`model_config` (including `extra="forbid"`), and field metadata (aliases, 
max_length, pattern, etc.)
   - Created `ConnectionBodyPartial`, `VariableBodyPartial`, and 
`DAGPatchBodyPartial` in their respective datamodel files
   - When `update_mask` is provided, validation runs only the masked fields 
against the partial model; when no `update_mask`, the full model validation is 
preserved
   
   All 346 existing tests pass (connections, dags, variables, pools), plus new 
tests for `make_partial_model` and endpoint-level partial validation.



##########
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())

Review Comment:
   Fixed — same approach applied here. `VariableBodyPartial` is used when 
`update_mask` is provided, so partial payloads no longer fail against the full 
`VariableBody` model's required `key` and `value` fields.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to