guan404ming commented on code in PR #54791: URL: https://github.com/apache/airflow/pull/54791#discussion_r2298456458
########## airflow-core/tests/unit/api_fastapi/core_api/services/public/test_task_instances.py: ########## @@ -0,0 +1,211 @@ +# 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 datetime as dt +from typing import TYPE_CHECKING + +import pytest + +from airflow._shared.timezones.timezone import datetime +from airflow.api_fastapi.core_api.datamodels.common import BulkBody +from airflow.api_fastapi.core_api.services.public.task_instances import BulkTaskInstanceService +from airflow.models import DagRun, TaskInstance +from airflow.models.dag_version import DagVersion +from airflow.utils.state import DagRunState, State +from airflow.utils.types import DagRunType + +from tests_common.test_utils.db import ( + clear_db_runs, +) + +pytestmark = pytest.mark.db_test + +DEFAULT = datetime(2020, 1, 1) +DEFAULT_DATETIME_STR_1 = "2020-01-01T00:00:00+00:00" +DEFAULT_DATETIME_STR_2 = "2020-01-02T00:00:00+00:00" + +DEFAULT_DATETIME_1 = dt.datetime.fromisoformat(DEFAULT_DATETIME_STR_1) +DEFAULT_DATETIME_2 = dt.datetime.fromisoformat(DEFAULT_DATETIME_STR_2) + + +class TestTaskInstanceEndpoint: + @staticmethod + def clear_db(): + clear_db_runs() + + def create_task_instances( Review Comment: It seems that `create_task_instance` creates a new task instance in a separate dag run for each call, but we need all task instances to belong to the same run for the same dag in these tests. To simplify this, I switched to using `dag_maker.create_dagrun(run_id=DAG_RUN_ID) ` instead. Please Let me know if there's a better approach, happy to update! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
