-
Notifications
You must be signed in to change notification settings - Fork 17.1k
Introduce BaseTaskInstanceDTO and duplicate it across core and task-sdk #67174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
uranusjr
merged 1 commit into
apache:main
from
jason810496:task-sdk/feature/base-task-instance-dto
May 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # 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. | ||
| """ | ||
| Verify that the duplicate ``BaseTaskInstanceDTO`` definitions in airflow-core | ||
| and task-sdk stay structurally identical. | ||
|
|
||
| ``BaseTaskInstanceDTO`` is duplicated (not shared) in: | ||
|
|
||
| - ``airflow-core/src/airflow/executors/workloads/task.py`` | ||
| - ``task-sdk/src/airflow/sdk/execution_time/workloads/task.py`` | ||
|
|
||
| This hook compares the *fields* (annotated assignments) and bases of both | ||
| ``BaseTaskInstanceDTO`` classes. The concrete ``TaskInstanceDTO`` subclasses | ||
| in each file are allowed to differ (airflow-core adds an executor-specific | ||
| ``key`` property that depends on ``airflow.models``, which the Task SDK | ||
| does not have access to). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import ast | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| AIRFLOW_ROOT = Path(__file__).parents[3].resolve() | ||
| CORE_FILE = AIRFLOW_ROOT / "airflow-core" / "src" / "airflow" / "executors" / "workloads" / "task.py" | ||
| SDK_FILE = AIRFLOW_ROOT / "task-sdk" / "src" / "airflow" / "sdk" / "execution_time" / "workloads" / "task.py" | ||
| CLASS_NAME = "BaseTaskInstanceDTO" | ||
|
|
||
|
|
||
| def _find_class(tree: ast.AST, class_name: str) -> ast.ClassDef | None: | ||
| for node in ast.walk(tree): | ||
| if isinstance(node, ast.ClassDef) and node.name == class_name: | ||
| return node | ||
| return None | ||
|
|
||
|
|
||
| def _field_signature(class_node: ast.ClassDef) -> list[tuple[str, str, str | None]]: | ||
| """Return a normalized list of ``(name, annotation, default)`` for each field.""" | ||
| fields: list[tuple[str, str, str | None]] = [] | ||
| for stmt in class_node.body: | ||
| if isinstance(stmt, ast.AnnAssign) and isinstance(stmt.target, ast.Name): | ||
| name = stmt.target.id | ||
| annotation = ast.unparse(stmt.annotation) | ||
| default = ast.unparse(stmt.value) if stmt.value is not None else None | ||
| fields.append((name, annotation, default)) | ||
| return fields | ||
|
|
||
|
|
||
| def _bases(class_node: ast.ClassDef) -> list[str]: | ||
| return [ast.unparse(base) for base in class_node.bases] | ||
|
|
||
|
|
||
| def _extract(file_path: Path) -> tuple[list[str], list[tuple[str, str, str | None]]]: | ||
| source = file_path.read_text() | ||
| tree = ast.parse(source, filename=str(file_path)) | ||
| class_node = _find_class(tree, CLASS_NAME) | ||
| if class_node is None: | ||
| print(f"ERROR: Could not find class {CLASS_NAME} in {file_path}", file=sys.stderr) | ||
| sys.exit(1) | ||
| return _bases(class_node), _field_signature(class_node) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| core_bases, core_fields = _extract(CORE_FILE) | ||
| sdk_bases, sdk_fields = _extract(SDK_FILE) | ||
|
|
||
| if core_bases == sdk_bases and core_fields == sdk_fields: | ||
| sys.exit(0) | ||
|
|
||
| print( | ||
| f"\nERROR: {CLASS_NAME} definitions in airflow-core and task-sdk are out of sync!", | ||
| file=sys.stderr, | ||
| ) | ||
| print(f"\n airflow-core: {CORE_FILE.relative_to(AIRFLOW_ROOT)}", file=sys.stderr) | ||
| print(f" task-sdk: {SDK_FILE.relative_to(AIRFLOW_ROOT)}", file=sys.stderr) | ||
|
|
||
| if core_bases != sdk_bases: | ||
| print("\nClass bases differ:", file=sys.stderr) | ||
| print(f" airflow-core: {core_bases}", file=sys.stderr) | ||
| print(f" task-sdk: {sdk_bases}", file=sys.stderr) | ||
|
|
||
| if core_fields != sdk_fields: | ||
| core_set = {f[0]: f for f in core_fields} | ||
| sdk_set = {f[0]: f for f in sdk_fields} | ||
| only_in_core = sorted(set(core_set) - set(sdk_set)) | ||
| only_in_sdk = sorted(set(sdk_set) - set(core_set)) | ||
| differing = sorted(name for name in set(core_set) & set(sdk_set) if core_set[name] != sdk_set[name]) | ||
| if only_in_core: | ||
| print(f"\n Fields only in airflow-core: {only_in_core}", file=sys.stderr) | ||
| if only_in_sdk: | ||
| print(f"\n Fields only in task-sdk: {only_in_sdk}", file=sys.stderr) | ||
| for name in differing: | ||
| print( | ||
| f"\n Field {name!r} differs:" | ||
| f"\n airflow-core: {core_set[name]}" | ||
| f"\n task-sdk: {sdk_set[name]}", | ||
| file=sys.stderr, | ||
| ) | ||
|
|
||
| print( | ||
| f"\nUpdate both files together so the two {CLASS_NAME} definitions stay in sync.", | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
23 changes: 23 additions & 0 deletions
23
task-sdk/src/airflow/sdk/execution_time/workloads/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # 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. | ||
| """Workload schemas for Task SDK execution-time communication.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from airflow.sdk.execution_time.workloads.task import TaskInstanceDTO | ||
|
|
||
| __all__ = ["TaskInstanceDTO"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # 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. | ||
| """Task workload schemas for Task SDK execution-time communication.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import uuid | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
|
|
||
| class BaseTaskInstanceDTO(BaseModel): | ||
| """ | ||
| Base schema for TaskInstance with the minimal fields shared by Executors and the Task SDK. | ||
|
|
||
| This class is duplicated in :mod:`airflow.executors.workloads.task` and the | ||
| two definitions are kept in sync by the ``check-task-instance-dto-sync`` | ||
| prek hook. Update both files together. | ||
| """ | ||
|
|
||
| id: uuid.UUID | ||
| dag_version_id: uuid.UUID | ||
| task_id: str | ||
| dag_id: str | ||
| run_id: str | ||
| try_number: int | ||
| map_index: int = -1 | ||
|
|
||
| pool_slots: int | ||
| queue: str | ||
| priority_weight: int | ||
| executor_config: dict | None = Field(default=None, exclude=True) | ||
|
|
||
| parent_context_carrier: dict | None = None | ||
| context_carrier: dict | None = None | ||
|
|
||
|
|
||
| class TaskInstanceDTO(BaseTaskInstanceDTO): | ||
| """Task SDK TaskInstanceDTO.""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.