Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on PR #50443: URL: https://github.com/apache/airflow/pull/50443#issuecomment-2919967477 Thanks for all reviews and suggestions. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
bbovenzi merged PR #50443: URL: https://github.com/apache/airflow/pull/50443 -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2113827099 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,271 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session Review Comment: Thanks! My bad and I would update it now  -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on PR #50443: URL: https://github.com/apache/airflow/pull/50443#issuecomment-2919463477 It works, thanks @jason810496 ! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2113827559 ## kubernetes-tests/tests/kubernetes_tests/test_base.py: ## @@ -232,20 +232,44 @@ def ensure_resource_health( resource_name: str, namespace: str = "airflow", resource_type: Literal["deployment", "statefulset"] = "deployment", +max_retries: int = 3, +timeout_seconds: int = 5, ): """Watch the resource until it is healthy. Args: resource_name (str): Name of the resource to check. resource_type (str): Type of the resource (e.g., deployment, statefulset). namespace (str): Kubernetes namespace where the resource is located. +max_retries (int): Maximum number of retries. +timeout_seconds (int): Timeout in seconds for each attempt. """ -rollout_status = check_output( -["kubectl", "rollout", "status", f"{resource_type}/{resource_name}", "-n", namespace, "--watch"], -).decode() -if resource_type == "deployment": -assert "successfully rolled out" in rollout_status -else: -assert "roll out complete" in rollout_status +for attempt in range(max_retries): +try: +rollout_status = check_output( +[ +"kubectl", +"rollout", +"status", +f"{resource_type}/{resource_name}", +"-n", Review Comment: Sure, I would remove it now. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2113827099 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,271 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session Review Comment: Thanks! It takes me lots of time to deal with this.  -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
jason810496 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2113743569 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,271 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session Review Comment: ```suggestion ``` Hi @guan404ming, I found the root cause of CI error. Dig into https://github.com/apache/airflow/actions/runs/15316975680/job/43093478689?pr=50443 with verbose full traceback. This is caused by accidentally import `pytest`! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
jason810496 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2113743569 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,271 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session Review Comment: ```suggestion ``` Hi @guan404ming, I found the root cause of CI error. Dig into https://github.com/apache/airflow/actions/runs/15316975680/job/43093478689?pr=50443 with verbose full traceback. This is caused by accidentally import of `pytest`! ## kubernetes-tests/tests/kubernetes_tests/test_base.py: ## @@ -232,20 +232,44 @@ def ensure_resource_health( resource_name: str, namespace: str = "airflow", resource_type: Literal["deployment", "statefulset"] = "deployment", +max_retries: int = 3, +timeout_seconds: int = 5, ): """Watch the resource until it is healthy. Args: resource_name (str): Name of the resource to check. resource_type (str): Type of the resource (e.g., deployment, statefulset). namespace (str): Kubernetes namespace where the resource is located. +max_retries (int): Maximum number of retries. +timeout_seconds (int): Timeout in seconds for each attempt. """ -rollout_status = check_output( -["kubectl", "rollout", "status", f"{resource_type}/{resource_name}", "-n", namespace, "--watch"], -).decode() -if resource_type == "deployment": -assert "successfully rolled out" in rollout_status -else: -assert "roll out complete" in rollout_status +for attempt in range(max_retries): +try: +rollout_status = check_output( +[ +"kubectl", +"rollout", +"status", +f"{resource_type}/{resource_name}", +"-n", Review Comment: So I think we can revert the change to k8s test. Or raise another PR for it. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2113198137 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,269 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) Review Comment: Thanks for pointing out. I’ve updated~ -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2113198137 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,269 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) Review Comment: This for pointing out. I’ve updated~ -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
jason810496 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2110719188 ## airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py: ## @@ -728,54 +731,6 @@ def post_clear_task_instances( ) -def _patch_ti_validate_request( -dag_id: str, -dag_run_id: str, -task_id: str, -dag_bag: DagBagDep, -body: PatchTaskInstanceBody, -session: SessionDep, -map_index: int | None = -1, -update_mask: list[str] | None = Query(None), -) -> tuple[DAG, list[TI], dict]: -dag = dag_bag.get_dag(dag_id) -if not dag: -raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") - -if not dag.has_task(task_id): -raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") - -query = ( -select(TI) -.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) -.join(TI.dag_run) -.options(joinedload(TI.rendered_task_instance_fields)) -) -if map_index is not None: -query = query.where(TI.map_index == map_index) -else: -query = query.order_by(TI.map_index) Review Comment: For old `_patch_ti_validate_request` implementation, here is `order_by` for the `else` case. ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,269 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) Review Comment: However, for the new one, we miss the `order_by` statement. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on PR #50443: URL: https://github.com/apache/airflow/pull/50443#issuecomment-2912266052 I've tried rebase it multiple times and I even add longer timeout and retry the k8s check but it seems not works. Let me rebase it again. Thanks! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
pierrejeambrun commented on PR #50443: URL: https://github.com/apache/airflow/pull/50443#issuecomment-2909885419 I'm not sure, did you try rebasing a couple of times, maybe that's no directly related because the server is not starting. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on PR #50443: URL: https://github.com/apache/airflow/pull/50443#issuecomment-2907921766 Hi, @pierrejeambrun @bugraoz93 I think the ci error do related to my change since it works normally on main and only fails here. But I couldn't find the root cause for it in several days of trying. Do you know any possible direction or something could cause k8s test crush? I could keep doing more research and testing. Thanks in advance! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on PR #50443: URL: https://github.com/apache/airflow/pull/50443#issuecomment-2891801446 Fixing ci, mark it as draft. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2096055329 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,285 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found.", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances( +self, task_ids: set +) -> tuple[dict[tuple[str, int], TI], set[str], set[str]]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +:param task_ids: set of task_ids +:return: tuple of (task_instances_map, matched_task_ids, not_found_task_ids) +""" +query = select(TI).where( +TI.dag_id == self.dag_id, TI.run_id == self.dag_run_id, TI.task_id.in_(task_ids) +) +task_instances = self.session.scalars(query).all() +task_instances_map = { +(ti.task_id, ti.map_index if ti.map_index is not
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2096058079 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,285 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found.", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances( +self, task_ids: set +) -> tuple[dict[tuple[str, int], TI], set[str], set[str]]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +:param task_ids: set of task_ids +:return: tuple of (task_instances_map, matched_task_ids, not_found_task_ids) +""" +query = select(TI).where( +TI.dag_id == self.dag_id, TI.run_id == self.dag_run_id, TI.task_id.in_(task_ids) +) +task_instances = self.session.scalars(query).all() +task_instances_map = { +(ti.task_id, ti.map_index if ti.map_index is not
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2096055329 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,285 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found.", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances( +self, task_ids: set +) -> tuple[dict[tuple[str, int], TI], set[str], set[str]]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +:param task_ids: set of task_ids +:return: tuple of (task_instances_map, matched_task_ids, not_found_task_ids) +""" +query = select(TI).where( +TI.dag_id == self.dag_id, TI.run_id == self.dag_run_id, TI.task_id.in_(task_ids) +) +task_instances = self.session.scalars(query).all() +task_instances_map = { +(ti.task_id, ti.map_index if ti.map_index is not
Re: [PR] Add TI bulk actions endpoint [airflow]
pierrejeambrun commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2095678496 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,285 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found.", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances( +self, task_ids: set +) -> tuple[dict[tuple[str, int], TI], set[str], set[str]]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +:param task_ids: set of task_ids +:return: tuple of (task_instances_map, matched_task_ids, not_found_task_ids) +""" +query = select(TI).where( +TI.dag_id == self.dag_id, TI.run_id == self.dag_run_id, TI.task_id.in_(task_ids) +) +task_instances = self.session.scalars(query).all() +task_instances_map = { +(ti.task_id, ti.map_index if ti.map_index is n
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2093574505 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,249 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute(select(TI).filter(TI.task_id.in_(task_ids))).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in existed
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2093573587 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,249 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute(select(TI).filter(TI.task_id.in_(task_ids))).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in existed
Re: [PR] Add TI bulk actions endpoint [airflow]
pierrejeambrun commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2093195168 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,249 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute(select(TI).filter(TI.task_id.in_(task_ids))).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in exis
Re: [PR] Add TI bulk actions endpoint [airflow]
jason810496 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2093186704 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,249 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute(select(TI).filter(TI.task_id.in_(task_ids))).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in existed
Re: [PR] Add TI bulk actions endpoint [airflow]
pierrejeambrun commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2093182439 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,249 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +import structlog +from fastapi import HTTPException, Query, status +from fastapi.exceptions import RequestValidationError +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select +from sqlalchemy.orm import joinedload + +from airflow.api_fastapi.common.dagbag import DagBagDep +from airflow.api_fastapi.common.db.common import SessionDep +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody, PatchTaskInstanceBody +from airflow.api_fastapi.core_api.security import GetUserDep +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.listeners.listener import get_listener_manager +from airflow.models.dag import DAG +from airflow.models.taskinstance import TaskInstance as TI +from airflow.utils.state import TaskInstanceState + +log = structlog.get_logger(__name__) + + +def _patch_ti_validate_request( +dag_id: str, +dag_run_id: str, +task_id: str, +dag_bag: DagBagDep, +body: PatchTaskInstanceBody, +session: SessionDep, +map_index: int | None = -1, +update_mask: list[str] | None = Query(None), +) -> tuple[DAG, list[TI], dict]: +dag = dag_bag.get_dag(dag_id) +if not dag: +raise HTTPException(status.HTTP_404_NOT_FOUND, f"DAG {dag_id} not found") + +if not dag.has_task(task_id): +raise HTTPException(status.HTTP_404_NOT_FOUND, f"Task '{task_id}' not found in DAG '{dag_id}'") + +query = ( +select(TI) +.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id) +.join(TI.dag_run) +.options(joinedload(TI.rendered_task_instance_fields)) +) +if map_index is not None: +query = query.where(TI.map_index == map_index) + +tis = session.scalars(query).all() + +err_msg_404 = ( +f"The Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}` and map_index: `{map_index}` was not found", +) +if len(tis) == 0: +raise HTTPException(status.HTTP_404_NOT_FOUND, err_msg_404) + +fields_to_update = body.model_fields_set +if update_mask: +fields_to_update = fields_to_update.intersection(update_mask) +else: +try: +PatchTaskInstanceBody.model_validate(body) +except ValidationError as e: +raise RequestValidationError(errors=e.errors()) + +return dag, list(tis), body.model_dump(include=fields_to_update, by_alias=True) + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, +session: Session, +request: BulkBody[BulkTaskInstanceBody], +dag_id: str, +dag_run_id: str, +dag_bag: DagBagDep, +user: GetUserDep, +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id +self.dag_bag = dag_bag +self.user = user + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids Review Comment: ```suggestion :return: tuple of dict of existing task instances, set of matched task_ids, set of not found task_ids ``` ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_insta
Re: [PR] Add TI bulk actions endpoint [airflow]
bugraoz93 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2087451985 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,146 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.taskinstance import TaskInstance + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, session: Session, request: BulkBody[BulkTaskInstanceBody], dag_id: str, dag_run_id: str +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute( +select(TaskInstance).filter(TaskInstance.task_id.in_(task_ids)) +).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in existed_task_instances +} +matched_task_ids = set(existed_task_instances_dict.keys()) +not_found_task_ids = task_ids - matched_task_ids +return existed_task_instances_dict, matched_task_ids, not_found_task_ids + +def handle_bulk_create( +self, action: BulkCreateAction[BulkTaskInstanceBody], results: BulkActionResponse +) -> None: +results.errors.append( +{ +"error": "Task instances bulk create is not supported", +"status_code": status.HTTP_405_METHOD_NOT_ALLOWED, +} +) + +def handle_bulk_update( Review Comment: Nice, exactly, using this method comes with some additional changes indeed. Thanks! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2086862484 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,146 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.taskinstance import TaskInstance + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, session: Session, request: BulkBody[BulkTaskInstanceBody], dag_id: str, dag_run_id: str +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute( +select(TaskInstance).filter(TaskInstance.task_id.in_(task_ids)) +).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in existed_task_instances +} +matched_task_ids = set(existed_task_instances_dict.keys()) +not_found_task_ids = task_ids - matched_task_ids +return existed_task_instances_dict, matched_task_ids, not_found_task_ids + +def handle_bulk_create( +self, action: BulkCreateAction[BulkTaskInstanceBody], results: BulkActionResponse +) -> None: +results.errors.append( +{ +"error": "Task instances bulk create is not supported", +"status_code": status.HTTP_405_METHOD_NOT_ALLOWED, +} +) + +def handle_bulk_update( Review Comment: I've moved the function into the service root level. I also notice that when patching in public route it does have some more verification than here. Thus, I tried to add them here but I'm not sure if it is necessary. Please let me know if I should keep it here or remove it and replace with the attribute setter. Thanks! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2086652107 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( Review Comment: Sure, thanks for the suggestion. I could work on that part after this one. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
bugraoz93 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2085366645 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,146 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.taskinstance import TaskInstance + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, session: Session, request: BulkBody[BulkTaskInstanceBody], dag_id: str, dag_run_id: str +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute( +select(TaskInstance).filter(TaskInstance.task_id.in_(task_ids)) +).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in existed_task_instances +} +matched_task_ids = set(existed_task_instances_dict.keys()) +not_found_task_ids = task_ids - matched_task_ids +return existed_task_instances_dict, matched_task_ids, not_found_task_ids + +def handle_bulk_create( +self, action: BulkCreateAction[BulkTaskInstanceBody], results: BulkActionResponse +) -> None: +results.errors.append( +{ +"error": "Task instances bulk create is not supported", +"status_code": status.HTTP_405_METHOD_NOT_ALLOWED, +} +) + +def handle_bulk_update( Review Comment: We should use the following method while updating the TI. Maybe, we can move this method to this service at the root level and call in routes from here, else a circular import. Also, we should call this method for each TI and else put it into the error list https://github.com/apache/airflow/blame/5db752bc4c0058bc68df0e9020f5f1365c0f679d/airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py#L732-L780 -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
bugraoz93 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2085366645 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,146 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.taskinstance import TaskInstance + + +class BulkTaskInstanceService(BulkService[BulkTaskInstanceBody]): +"""Service for handling bulk operations on task instances.""" + +def __init__( +self, session: Session, request: BulkBody[BulkTaskInstanceBody], dag_id: str, dag_run_id: str +): +super().__init__(session, request) +self.dag_id = dag_id +self.dag_run_id = dag_run_id + +def categorize_task_instances(self, task_ids: set) -> tuple[dict, set, set]: +""" +Categorize the given task_ids into matched_task_ids and not_found_task_ids based on existing task_ids. + +Existed task instances are returned as a dict of {task_id : TaskInstance}. + +:param task_ids: set of task_ids +:return: tuple of dict of existed task instances, set of matched task_ids, set of not found task_ids +""" +existed_task_instances = self.session.execute( +select(TaskInstance).filter(TaskInstance.task_id.in_(task_ids)) +).scalars() +existed_task_instances_dict = { +task_instance.task_id: task_instance for task_instance in existed_task_instances +} +matched_task_ids = set(existed_task_instances_dict.keys()) +not_found_task_ids = task_ids - matched_task_ids +return existed_task_instances_dict, matched_task_ids, not_found_task_ids + +def handle_bulk_create( +self, action: BulkCreateAction[BulkTaskInstanceBody], results: BulkActionResponse +) -> None: +results.errors.append( +{ +"error": "Task instances bulk create is not supported", +"status_code": status.HTTP_405_METHOD_NOT_ALLOWED, +} +) + +def handle_bulk_update( Review Comment: We should use the following method while updating the TI. Maybe, we can move this method to this service at the root level and call in routes from here, or else a circular import. Also, we should call this method for each TI and else put it into the error list. General looks good https://github.com/apache/airflow/blame/5db752bc4c0058bc68df0e9020f5f1365c0f679d/airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py#L732-L780 -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
bugraoz93 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2085349044 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( Review Comment: That would be ideal, but not mandatory for this PR. We can reevaluate that part in the future. Let's keep it at the root for now :+1: We don't need to increase the scope. That is a unique case for connection -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
bugraoz93 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2085349044 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( Review Comment: That would be ideal, but not mandatory for this PR. We can make all of them class methods in the future. Let's keep it at root for now :+1: We don't need to increase the scope -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
bugraoz93 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2085349044 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( Review Comment: That would be ideal, but not mandatory for this PR. We can make all of them class methods in the future. Let's keep it at root for now :+1: -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2083561629 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( +orm_conn: Connection, pydantic_conn: BulkTaskInstanceBody, update_mask: list[str] | None = None Review Comment: This is my fault and sorry for the confusion. I think what you say make sense. We could just set their attribute instead of dumping them. Thus I choose to remove the unused the func and using the for-loop to set. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2083562184 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( Review Comment: Should we also need to add test for connection since https://github.com/apache/airflow/blob/9e3a934b534f7bed4f148957d1d9822b88036679/airflow-core/src/airflow/api_fastapi/core_api/services/public/connections.py#L37 -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2083561788 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( Review Comment: Replaced by attribute setter. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2083561674 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( +orm_conn: Connection, pydantic_conn: BulkTaskInstanceBody, update_mask: list[str] | None = None Review Comment: My fault updated. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
guan404ming commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r2083561629 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( +orm_conn: Connection, pydantic_conn: BulkTaskInstanceBody, update_mask: list[str] | None = None Review Comment: My fault and I think what you say make sense. We could just set their attribute instead of dumping them. Thus I choose to remove the unused the func and using the for-loop to set. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Add TI bulk actions endpoint [airflow]
bugraoz93 commented on code in PR #50443: URL: https://github.com/apache/airflow/pull/50443#discussion_r208300 ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( +orm_conn: Connection, pydantic_conn: BulkTaskInstanceBody, update_mask: list[str] | None = None Review Comment: This method accepts a `Connection`, but `TaskInstance` is passed as `old_task_instance`. I think we should remove Connection here and as from imports in this file. This makes maybe `schema_` disappear ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import Session +from sqlalchemy import select + +from airflow.api_fastapi.core_api.datamodels.common import ( +BulkActionNotOnExistence, +BulkActionResponse, +BulkBody, +BulkCreateAction, +BulkDeleteAction, +BulkUpdateAction, +) +from airflow.api_fastapi.core_api.datamodels.task_instances import BulkTaskInstanceBody +from airflow.api_fastapi.core_api.services.public.common import BulkService +from airflow.models.connection import Connection +from airflow.models.taskinstance import TaskInstance + + +def update_orm_from_pydantic( +orm_conn: Connection, pydantic_conn: BulkTaskInstanceBody, update_mask: list[str] | None = None Review Comment: Why are these named as `_conn`? I am wondering why there is `schema_` in the fields since it doesn't even exist in the datamodel? ## airflow-core/src/airflow/api_fastapi/core_api/services/public/task_instances.py: ## @@ -0,0 +1,170 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from fastapi import HTTPException, status +from pydantic import ValidationError +from pytest import S