jason810496 commented on code in PR #54597:
URL: https://github.com/apache/airflow/pull/54597#discussion_r2372883955
##########
airflow-core/src/airflow/api_fastapi/core_api/services/public/common.py:
##########
@@ -72,3 +75,48 @@ def handle_bulk_update(self, action: BulkUpdateAction[T],
results: BulkActionRes
def handle_bulk_delete(self, action: BulkDeleteAction[T], results:
BulkActionResponse) -> None:
"""Bulk delete entities."""
raise NotImplementedError
+
+ @staticmethod
+ def apply_patch_with_update_mask(
+ model: DeclarativeMeta,
+ patch_body: BaseModel,
+ update_mask: list[str] | None,
+ non_update_fields: set[str] | None = None,
+ ) -> DeclarativeMeta:
+ """
+ Apply a patch to the given model using the provided update mask.
+
+ :param model: The SQLAlchemy model instance to update.
+ :param patch_body: Pydantic model containing patch data.
+ :param update_mask: Optional list of fields to update.
+ :param non_update_fields: Fields that should not be updated.
+ :return: The updated SQLAlchemy model instance.
+ :raises HTTPException: If invalid fields are provided in update_mask.
+ """
+ # Always dump without aliases for internal validation
+ raw_data = patch_body.model_dump(by_alias=False)
+ fields_to_update = set(patch_body.model_fields_set)
+
+ non_update_fields = non_update_fields or set()
+
+ if update_mask:
+ restricted_in_mask =
set(update_mask).intersection(non_update_fields)
+ if restricted_in_mask:
+ raise HTTPException(
+ status_code=status.HTTP_400_BAD_REQUEST,
+ detail=f"Update not allowed: the following fields are
immutable and cannot be modified:{restricted_in_mask}",
Review Comment:
```suggestion
detail=f"Update not allowed: the following fields are
immutable and cannot be modified: {restricted_in_mask}",
```
--
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]