From cd5ccf0abf5027cf457b36a8a2bee397dcb538b4 Mon Sep 17 00:00:00 2001 From: Ash Berlin-Taylor Date: Fri, 29 Nov 2024 15:48:35 +0000 Subject: [PATCH] Fix flakey test in DAG serialization (#44480) This behaviour is very odd, and is not in anyway clear _why_ it's happening, but the fix is to not construct a DAG object, but to use attrs to tell us what the fields are -- which is better behaviour anyway. To reproduce the issue before this change: 1. `pytest tests/serialization/test_dag_serialization.py::TestStringifiedDAGs::test_deserialization_with_dag_context` -> greeen 2. `pytest tests/serialization/test_dag_serialization.py::TestStringifiedDAGs::test_deserialization_with_dag_context` -> boom (So by dag objects existing in the DB it somehow "poluted" the DagContextManager/TaskContextManager stack. I haven't dug into exactly how that might be happening.) --- task_sdk/src/airflow/sdk/definitions/dag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task_sdk/src/airflow/sdk/definitions/dag.py b/task_sdk/src/airflow/sdk/definitions/dag.py index 20621ba148fbd..d02480c8ab1bc 100644 --- a/task_sdk/src/airflow/sdk/definitions/dag.py +++ b/task_sdk/src/airflow/sdk/definitions/dag.py @@ -991,7 +991,7 @@ def get_serialized_fields(cls): "fail_stop", "schedule", } - cls.__serialized_fields = frozenset(vars(DAG(dag_id="test", schedule=None))) - exclusion_list + cls.__serialized_fields = frozenset(a.name for a in attrs.fields(cls)) - exclusion_list return cls.__serialized_fields def get_edge_info(self, upstream_task_id: str, downstream_task_id: str) -> EdgeInfoType: