sortega commented on code in PR #68568:
URL: https://github.com/apache/airflow/pull/68568#discussion_r3551718473
##########
task-sdk/tests/task_sdk/execution_time/test_task_runner.py:
##########
@@ -6267,3 +6284,49 @@ def test_bad_declaration_is_skipped_not_fatal(self):
with patch("airflow.sdk.execution_time.task_runner.allow_class",
side_effect=ValueError("nope")):
# Must not raise -- the walk swallows per-class registration
errors.
_register_deserialization_allowed_classes(dag,
structlog.get_logger())
+
+
+def _make_dag_tagged_ti(create_runtime_ti, tags):
+ """Build a RuntimeTaskInstance whose in-memory Dag carries the given
tags."""
+ from airflow.sdk import DAG
+ from airflow.sdk.bases.operator import BaseOperator
+
+ class _NoopOperator(BaseOperator):
+ def execute(self, context):
+ return None
+
+ with DAG("tagged_dag", tags=tags):
+ task = _NoopOperator(task_id="t")
+ return create_runtime_ti(task=task)
+
+
+def test_stats_tags_dag_tags_disabled_by_default(create_runtime_ti):
+ """With the flag off (the default), dag tags must not leak into metrics."""
+ ti = _make_dag_tagged_ti(create_runtime_ti, ["env:prod", "validation"])
+ assert ti.stats_tags == {"dag_id": "tagged_dag", "task_id": "t",
"run_type": "manual"}
+
+
+@conf_vars({("metrics", "dag_tags_in_metrics"): "True"})
+def test_stats_tags_without_dag_tags(create_runtime_ti):
+ ti = _make_dag_tagged_ti(create_runtime_ti, [])
+ assert ti.stats_tags == {"dag_id": "tagged_dag", "task_id": "t",
"run_type": "manual"}
+
+
+@conf_vars({("metrics", "dag_tags_in_metrics"): "True"})
+def test_stats_tags_with_standalone_and_key_value_tags(create_runtime_ti):
+ ti = _make_dag_tagged_ti(create_runtime_ti, ["env:prod", "validation"])
+ assert ti.stats_tags == {
+ "env": "prod",
+ "validation": "",
+ "dag_id": "tagged_dag",
+ "task_id": "t",
+ "run_type": "manual",
+ }
+
+
+def test_stats_tags_run_type_is_bare_string(create_runtime_ti):
+ """run_type must be the bare DagRunType value (e.g. 'manual'), not the
enum — otherwise it
+ serializes as 'dagruntype.manual' on the wire and disagrees with the
scheduler-side tag."""
+ run_type = _make_dag_tagged_ti(create_runtime_ti,
[]).stats_tags["run_type"]
+ assert run_type == "manual"
+ assert type(run_type) is str # plain str, not a DagRunType enum member
Review Comment:
Dropped the separate test fn.
--
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]