Skip to content

Add default parameter to task and asset state get() accessors#67842

Merged
amoghrajesh merged 4 commits into
apache:mainfrom
astronomer:aip-103-backlog-default-return-value
Jun 3, 2026
Merged

Add default parameter to task and asset state get() accessors#67842
amoghrajesh merged 4 commits into
apache:mainfrom
astronomer:aip-103-backlog-default-return-value

Conversation

@amoghrajesh
Copy link
Copy Markdown
Contributor

@amoghrajesh amoghrajesh commented Jun 1, 2026


Was generative AI tooling used to co-author this PR?
  • Yes: claude sonnet 4.6

closes: #67841

What?

TaskStoreAccessor.get() and AssetStoreAccessor.get() returned None when a key did not exist, which made callers to use None checks or or based fallbacks like state.get("watermark") or "2026-01-01". This is not the best authoring experience and does not follow the standard Python dict.get(key, default) pattern.

Current behaviour

state.get("watermark") returns None if the key has never been set. Callers must write state.get("watermark") or "fallback", which is both verbose for no benefit.

Proposed change

  • Added a default parameter to get() on TaskStoreAccessor and AssetStoreAccessor, and the AssetStoreAccessors shorthand accessor. The default is None. Example usage:
state = context["task_store"]
watermark = state.get("watermark", default="2026-01-01T00:00:00+00:00")
total_runs = state.get("total_runs", default=0)
  • set(key, None) now raises ValueError — None is not a valid state value

The example dag example_asset_store.py is updated to use the new form.


  • Read the 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) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Copy link
Copy Markdown
Collaborator

@jroachgolf84 jroachgolf84 left a comment

Choose a reason for hiding this comment

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

LGTM! Excellent addition :)

Comment thread task-sdk/src/airflow/sdk/execution_time/context.py
(cherry picked from commit 57454d118a913b9feabbab58ae673843c4239690)
@amoghrajesh amoghrajesh requested a review from kaxil June 2, 2026 08:04
@amoghrajesh amoghrajesh moved this from Backlog to In review in AIP-103: Task State Management Jun 2, 2026
@amoghrajesh
Copy link
Copy Markdown
Contributor Author

The failures are unrelated, merging

@amoghrajesh amoghrajesh merged commit 99d88c1 into apache:main Jun 3, 2026
110 of 113 checks passed
@amoghrajesh amoghrajesh deleted the aip-103-backlog-default-return-value branch June 3, 2026 03:32
@github-project-automation github-project-automation Bot moved this from In review to Done in AIP-103: Task State Management Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

Add default parameter to get methods?

4 participants