pierrejeambrun commented on code in PR #57441:
URL: https://github.com/apache/airflow/pull/57441#discussion_r2581596461
##########
airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py:
##########
@@ -265,74 +411,83 @@ def handle_bulk_delete(
self, action: BulkDeleteAction[BulkTaskInstanceBody], results:
BulkActionResponse
) -> None:
"""Bulk delete task instances."""
- delete_all_map_indexes: set[str] = set()
- delete_specific_task_keys: set[tuple[str, int]] = set()
-
- for entity in action.entities:
- if isinstance(entity, str):
- # String task ID - remove all task instances for this task
- delete_all_map_indexes.add(entity)
- else:
- # BulkTaskInstanceBody object
- if entity.map_index is None:
- delete_all_map_indexes.add(entity.task_id)
- else:
- delete_specific_task_keys.add((entity.task_id,
entity.map_index))
+ # Validate and categorize entities into specific and all map index
delete sets
+ delete_specific_map_index_task_keys, delete_all_map_index_task_keys =
self._categorize_entities(
+ action.entities, results
+ )
try:
- # Handle deletion of specific (task_id, map_index) pairs
- if delete_specific_task_keys:
- _, matched_task_keys, not_found_task_keys =
self.categorize_task_instances(
- delete_specific_task_keys
+ # Handle deletion of specific (dag_id, dag_run_id, task_id,
map_index) tuples
+ if delete_specific_map_index_task_keys:
+ _, matched_task_keys, not_found_task_keys =
self._categorize_task_instances(
+ delete_specific_map_index_task_keys
)
- not_found_task_ids = [f"{task_id}[{map_index}]" for task_id,
map_index in not_found_task_keys]
+ not_found_task_ids = [
+ {"dag_id": dag_id, "dag_run_id": run_id, "task_id":
task_id, "map_index": map_index}
+ for dag_id, run_id, task_id, map_index in
not_found_task_keys
+ ]
if action.action_on_non_existence ==
BulkActionNotOnExistence.FAIL and not_found_task_keys:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
- detail=f"The task instances with these task_ids:
{not_found_task_ids} were not found",
+ detail=f"The task instances with these identifiers:
{not_found_task_ids} were not found",
)
- for task_id, map_index in matched_task_keys:
- result = (
+ for dag_id, run_id, task_id, map_index in matched_task_keys:
+ ti = (
self.session.execute(
select(TI).where(
+ TI.dag_id == dag_id,
+ TI.run_id == run_id,
TI.task_id == task_id,
- TI.dag_id == self.dag_id,
- TI.run_id == self.dag_run_id,
TI.map_index == map_index,
)
)
.scalars()
.one_or_none()
)
- if result:
- existing_task_instance = result
- self.session.delete(existing_task_instance)
+ if ti:
+ self.session.delete(ti)
results.success.append(f"{task_id}[{map_index}]")
Review Comment:
In the results here we probably want dag_id and run_id too, since now they
can be different between items.
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/common.py:
##########
@@ -92,7 +91,7 @@ class BulkDeleteAction(BulkBaseAction[T]):
"""Bulk Delete entity serializer for request bodies."""
action: Literal[BulkAction.DELETE] = Field(description="The action to be
performed on the entities.")
- entities: list[Union[str, BulkTaskInstanceBody]] = Field(
+ entities: list[Union[str, T]] = Field(
Review Comment:
Thanks for the fix.
--
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]