This is an automated email from the ASF dual-hosted git repository.
kaxilnaik pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 9fcba3da080 Fix bug in Serialization of templated fields set at
Runtime (#49144)
9fcba3da080 is described below
commit 9fcba3da080fabcbd0eab201666f8756b724e3a5
Author: Kaxil Naik <[email protected]>
AuthorDate: Sat Apr 12 12:10:03 2025 +0530
Fix bug in Serialization of templated fields set at Runtime (#49144)
closes https://github.com/apache/airflow/issues/49100
---------
Co-authored-by: vatsrahul1001 <[email protected]>
---
.../src/airflow/example_dags/example_bash_decorator.py | 2 +-
task-sdk/src/airflow/sdk/execution_time/task_runner.py | 4 +---
.../tests/task_sdk/execution_time/test_task_runner.py | 16 +++++++++++++---
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/airflow-core/src/airflow/example_dags/example_bash_decorator.py
b/airflow-core/src/airflow/example_dags/example_bash_decorator.py
index af7ff5c9f39..7448299e1a8 100644
--- a/airflow-core/src/airflow/example_dags/example_bash_decorator.py
+++ b/airflow-core/src/airflow/example_dags/example_bash_decorator.py
@@ -91,7 +91,7 @@ def example_bash_decorator():
def _get_files_in_cwd() -> list[str]:
from pathlib import Path
- dir_contents = Path.cwd().glob("airflow/example_dags/*.py")
+ dir_contents =
Path.cwd().glob("airflow-core/src/airflow/example_dags/*.py")
files = [str(elem) for elem in dir_contents if elem.is_file()]
return files
diff --git a/task-sdk/src/airflow/sdk/execution_time/task_runner.py
b/task-sdk/src/airflow/sdk/execution_time/task_runner.py
index f6758d7ca59..344746c63b0 100644
--- a/task-sdk/src/airflow/sdk/execution_time/task_runner.py
+++ b/task-sdk/src/airflow/sdk/execution_time/task_runner.py
@@ -1144,9 +1144,7 @@ def finalize(
if ti.task.template_fields:
SUPERVISOR_COMMS.send_request(
log=log,
- msg=SetRenderedFields(
- rendered_fields={field: getattr(ti.task, field) for field
in ti.task.template_fields}
- ),
+
msg=SetRenderedFields(rendered_fields=_serialize_rendered_fields(ti.task)),
)
log.debug("Running finalizers", ti=ti)
diff --git a/task-sdk/tests/task_sdk/execution_time/test_task_runner.py
b/task-sdk/tests/task_sdk/execution_time/test_task_runner.py
index d3f6cd90bde..b070c79150b 100644
--- a/task-sdk/tests/task_sdk/execution_time/test_task_runner.py
+++ b/task-sdk/tests/task_sdk/execution_time/test_task_runner.py
@@ -57,6 +57,7 @@ from airflow.sdk.api.datamodels._generated import (
TerminalTIState,
)
from airflow.sdk.bases.xcom import BaseXCom
+from airflow.sdk.definitions._internal.types import SET_DURING_EXECUTION
from airflow.sdk.definitions.asset import Asset, AssetAlias, Dataset, Model
from airflow.sdk.definitions.param import DagParam
from airflow.sdk.exceptions import ErrorType
@@ -1354,7 +1355,16 @@ class TestRuntimeTaskInstance:
map_index=runtime_ti.map_index,
)
- def test_overwrite_rtif_after_execution_sets_rtif(self, create_runtime_ti,
mock_supervisor_comms):
+ @pytest.mark.parametrize(
+ ["cmd", "rendered_cmd"],
+ [
+ pytest.param("echo 'hi'", "echo 'hi'", id="no_template_fields"),
+ pytest.param(SET_DURING_EXECUTION,
SET_DURING_EXECUTION.serialize(), id="with_default"),
+ ],
+ )
+ def test_overwrite_rtif_after_execution_sets_rtif(
+ self, create_runtime_ti, mock_supervisor_comms, cmd, rendered_cmd
+ ):
"""Test that the RTIF is overwritten after execution for certain
operators."""
class CustomOperator(BaseOperator):
@@ -1365,7 +1375,7 @@ class TestRuntimeTaskInstance:
self.bash_command = bash_command
super().__init__(*args, **kwargs)
- task = CustomOperator(task_id="hello", bash_command="echo 'hi'")
+ task = CustomOperator(task_id="hello", bash_command=cmd)
runtime_ti = create_runtime_ti(task=task)
finalize(
@@ -1376,7 +1386,7 @@ class TestRuntimeTaskInstance:
)
mock_supervisor_comms.send_request.assert_called_with(
- msg=SetRenderedFields(rendered_fields={"bash_command": "echo
'hi'"}),
+ msg=SetRenderedFields(rendered_fields={"bash_command":
rendered_cmd}),
log=mock.ANY,
)