Skip to content

Reject invalid partition keys in the create asset events API#69453

Open
Lee-W wants to merge 1 commit into
apache:mainfrom
astronomer:validate-asset-event-partition-key
Open

Reject invalid partition keys in the create asset events API#69453
Lee-W wants to merge 1 commit into
apache:mainfrom
astronomer:validate-asset-event-partition-key

Conversation

@Lee-W

@Lee-W Lee-W commented Jul 6, 2026

Copy link
Copy Markdown
Member

Why

POST /assets/events accepted any partition_key without validation. Two bad cases slipped through:

  • Empty or whitespace-only keys were silently stored as-is.
  • Keys longer than ID_LEN (250) chars hit the database column-length limit and surfaced as a 500 Internal Server Error, leaking an internal failure instead of telling the client the input was invalid.

The Execution API already validates this field; the public API should behave the same way.

What

  • Add a field_validator on CreateAssetEventsBody.partition_key that rejects empty / whitespace-only values and values exceeding ID_LEN, returning 422 instead of storing bad data or raising 500.
  • None remains valid (the field stays optional), so non-partitioned events are unaffected.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude] following the guidelines


  • 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.

POST /assets/events accepted any partition_key, silently storing empty/whitespace-only keys and letting keys over 250 characters hit a database column-length error as a 500. Validate the field the same way the Execution API already does, returning 422 instead.
@boring-cyborg boring-cyborg Bot added the area:API Airflow's REST/HTTP API label Jul 6, 2026
@Lee-W Lee-W added the backport-to-v3-3-test Backport to v3-3-test label Jul 6, 2026
@Lee-W Lee-W self-assigned this Jul 6, 2026

@jason810496 jason810496 left a comment

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.

IIUC, introducing Field would be sufficient enough.

"""Create asset events request."""

asset_id: int
partition_key: str | None = None

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.

Suggested change
partition_key: str | None = Field(default=None, max_length=ID_LEN)

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

Labels

area:API Airflow's REST/HTTP API backport-to-v3-3-test Backport to v3-3-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants