Skip to content

Add ADR for referencing a Python value - #77973

Open
uranusjr wants to merge 2 commits into
apache:mainfrom
astronomer:yaml-callbacks
Open

uranusjr wants to merge 2 commits into
apache:mainfrom
astronomer:yaml-callbacks

Conversation

@uranusjr

@uranusjr uranusjr commented Dec 2, 2026

Copy link
Copy Markdown
Member

ADR-0002 is proposed. A $import value marker that imports a Python object by its import path, and calls it when args or kwargs is given. It is recognized under a task's with: and on on_*_callback keys. This unblocks callbacks and notifiers in YAML Dags, operator arguments that must be Python objects, and operators that take a callable such as PythonOperator, which DagFactory Dags commonly use.

ADR-0003 is in draft. It sketches how references could later resolve in other languages, selected through queue routing (AIP-108, #76303) rather than by naming a language. It is not proposed for acceptance.

Review ADR-0002 in full. Consider ADR-0003 only on whether ADR-0002 leaves enough room for that direction. The details shall be discussed later, when the ADR is formally proposed.

This depends on the ADR-0001 amendment in #77944. ADR-0002 Decision 7 relies on literal $expand rows following the rules of with:.

@uranusjr uranusjr added this to the Airflow 3.5.0 milestone Dec 2, 2026
ADR-0002 adds the $import value marker. It imports a Python object by
its import path, and optionally calls it when args or kwargs is given.
It is recognized under a task's with: and on callback keys, so a YAML
Dag can set callbacks, operator arguments, etc. that must be Python
objects, such as PythonOperator's python_callable.

ADR-0003 (draft) sketches how references in other languages could be
added later, selected through queue routing rather than a language
name. This is provided both as notes for future design, and a reference
for reviewers to judge whether ADR-0002 leaves enough room for it.
Being a draft, the ADR is not proposed for acceptance, and suggestions
toward its content should be avoided unless they also affect the content
of ADR-0002.
- Either may be left out when it would be empty: `{$import: f, args: [1]}` is `f(1)`, and `{$import: f, kwargs: {x: 1}}` is `f(x=1)`. Both are needed only when both kinds of arguments are given.
- `args` is a list or null, and `kwargs` a mapping or null. Null and empty both mean no arguments of that kind, so `{$import: f, args:}`, `{$import: f, kwargs:}`, and a mapping with both empty all mean `f()`.

3. **`args` and `kwargs` are the marker's only options.**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the question for this PR, but do you think we need to add args on non-Python SDK Dag authoring interface? Or just keep them as kwargs only (current proposed state)?

- `runtime: dag`, the default, is the language the team's default queue routes to. This is what ADR-0002's `$import` means, a Python callback, so documents written for ADR-0002 keep their meaning.
- `runtime: task` is the language the task's own queue routes to: the handler's for a `run:` task, and the operator's for a `uses:` task once an operator can be written in another language.
- The option is the same on both task kinds, and optional on both. Running a callback with the task's definition is what every SDK does, so `dag` is a lasting default, not a placeholder.
- `runtime` selects the language that resolves the reference, not where the callback runs. Where a callback runs follows Airflow's rules: in the task's process, or for a routed callback, on the queue #76303 picks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking from the Lang-SDK world where I kept the Python as special one (python.callbackRef) whereas the YAML Dag we consider Python is the default and the non-Python callback is special.

Would it make sense to have the second primitive for the non-Python callable import as the special case?

on_retry_callback:
  # only $lang_sdk_import primitive allow using the "queue" arg
  - {$lang_sdk_import:  go_pkg.alerts.Notify, kwargs: {level: warn} queue: go}

IIRC, the runtime is what we avoid in the very first place of Lang-SDK. Though the purpose of the runtime here is sightly different.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants