Naman-Gururani opened a new pull request, #77728:
URL: https://github.com/apache/airflow/pull/77728
closes: #50003
Right now `outlet_events[asset]` returns an accessor for any asset or alias.
If it isn't one of the task's outlets, the event is still sent, but the API
server only registers events for the task's outlets, so it gets dropped without
any error. As discussed in the issue, this makes it raise a `KeyError` instead,
with a hint to add the asset to the task's outlets.
- `OutletEventAccessors` now gets the task's outlets (`task_runner` passes
`self.task.outlets`), and `__getitem__` checks them before creating an accessor.
- Outlets are matched the same way the API server matches them when it
registers events: `Asset` by name and URI, `Asset.ref` by name or URI,
`AssetAlias` by name. So it only raises when the event would be dropped anyway.
- `yield Metadata(...)` goes through the same accessor, so it's covered too.
It also lines up with `inlet_events`, which already raises `KeyError` for
assets that aren't inlets.
- The outlets list is kept by reference, so outlets added while the task
runs still count. Accessors created outside a task run (`outlets=None`) skip
the check.
One behaviour change, from the thread: a TaskFlow task that sets
`outlet_events[report]` and then returns `report`, without `outlets=[report]`,
works today because `_handle_output` adds the returned asset to the outlets
after the function returns. I ran that example on current main (the event goes
out with `extra={"rows": 42}`) and with this change (the task fails with the
new `KeyError`). Adding `outlets=[report]` fixes it. If you'd rather keep that
working, I can switch to checking after execution and logging a warning instead.
Tests: new cases in `test_context.py` (declared outlets of each kind are
accepted; undeclared assets, refs and aliases raise) and `test_task_runner.py`
(a task's `outlet_events` only accepts its outlets). They fail without the
change. `test_context.py`, `test_task_runner.py` and `test_asset_decorators.py`
pass locally in Docker, apart from 8 state-store tests that can't import
`airflow_shared` in my task-sdk-only env (same on main). ruff and mypy are
clean.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
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]