jroachgolf84 opened a new pull request, #67619:
URL: https://github.com/apache/airflow/pull/67619
## Description
This change ensures that if a Task only "outlets" an Asset, this Asset is
available in `context["asset_state"]`. Previously, if a Task only had `outlets`
and not `inlets`, subscripting `context["asset_state"]` returns a `KeyError`.
This is no longer the case!
## Testing
These changes were tested E2E, as well as via updated unit tests.
### Unit Tests
Four unit-tests were added as part of this PR. There were:
- `test_outlet_only_asset_is_accessible`
- `test_outlet_only_uri_ref_is_accessible`
- `test_outlet_only_single_shorthand_works`
- `test_asset_in_both_inlets_and_outlets_not_duplicated`
- `test_outlet_alias_is_ignored`
These can be run using the following command:
```bash
breeze testing core-tests
task-sdk/tests/task_sdk/execution_time/test_context.py
```
### E2E with a DAG
```python
from airflow.sdk import Asset, DAG, task
from datetime import datetime
my_asset = Asset(name="my_asset")
with DAG(
dag_id="fix_asset_outlet_keyerror",
start_date=datetime(2026, 1, 1),
schedule="@once"
) as dag:
@task(outlets=[my_asset])
def retrieve_asset_state(**context):
asset_state = context["asset_state"][my_asset]
asset_state.set("my_key", "my_value")
my_value = asset_state.get("my_key")
print(f"***** my_value: {my_value}")
retrieve_asset_state()
```
--
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]