seanghaeli commented on code in PR #76859:
URL: https://github.com/apache/airflow/pull/76859#discussion_r4651766751
##########
airflow-core/src/airflow/serialization/definitions/dag.py:
##########
@@ -185,6 +190,15 @@ def timetable(self, value: Timetable) -> None:
self._timetable = value
self._encoded_timetable = None
+ def get_template_env(self, *, force_sandboxed: bool = False) ->
jinja2.Environment:
Review Comment:
Nothing on the trigger path calls this. `BaseTrigger.render_template_fields`
(`triggers/base.py:166`) calls `self.get_template_env()` with no Dag, so it
gets a bare `SandboxedEnvironment`. I ran it in Breeze with
`user_defined_macros={"team": "data-eng"}` and a `start_from_trigger` task with
`{{ team }}` in its trigger kwargs: the trigger got `''` on both main and this
PR, even though `serialized_dag` now has `{"team": "data-eng"}`. Passing the
task's Dag there (`self.get_template_env(dag=self.task.dag if self.task else
None)`) made it render `data-eng`, so that plus a test that renders through the
trigger would cover it.
##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -1966,6 +1975,30 @@ def get_dag_optional_fields_from_schema(cls) -> set[str]:
optional_fields = operator_fields - required_fields
return optional_fields
+ @classmethod
+ def _serialize_user_defined_macros(cls, dag_id: str, macros: dict) -> dict:
+ """Filter *macros* down to JSON-safe primitives; drop callables at
DEBUG level."""
+ import json as _json
+
+ safe: dict = {}
+ dropped: list[str] = []
+ for key, value in macros.items():
+ if callable(value):
+ dropped.append(key)
+ continue
+ try:
+ _json.dumps(value)
Review Comment:
`float("nan")` gets through this check, but Postgres won't take it (`invalid
input syntax for type json ... Token "NaN" is invalid`). The whole Dag then
disappears: no `serialized_dag` row, nothing in `/api/v2/dags`, and no import
error. On main the same Dag parses and runs. `_json.dumps(value,
allow_nan=False)` would drop it like the other values that can't be serialized.
--
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]