Skip to content

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

Merged
Lee-W merged 5 commits into
apache:mainfrom
astronomer:validate-asset-event-partition-key
Jul 8, 2026
Merged

Reject invalid partition keys in the create asset events API#69453
Lee-W merged 5 commits 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.

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

Comment thread airflow-core/src/airflow/api_fastapi/core_api/datamodels/assets.py Outdated
@Lee-W Lee-W force-pushed the validate-asset-event-partition-key branch 2 times, most recently from 5adb78a to 6f1998e Compare July 7, 2026 09:03
@Lee-W Lee-W requested a review from jason810496 July 7, 2026 09:11
Comment thread airflow-core/src/airflow/api_fastapi/core_api/datamodels/assets.py Outdated
Lee-W added 5 commits July 7, 2026 19:08
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.
Remove the now-dead-code max_length check in validate_partition_key,
since Field(max_length=ID_LEN) already enforces it before the
after-mode field_validator runs. Also regenerate the OpenAPI spec and
downstream clients (UI, airflow-ctl) to reflect the maxLength
constraint added in the prior fixup commit.
Use a pydantic pattern constraint that rejects empty/whitespace-only
keys without altering valid ones, matching the Execution API's
outlet-event validation so both paths store identical values for the
same input.
@Lee-W Lee-W force-pushed the validate-asset-event-partition-key branch from 6f1998e to 87b67b3 Compare July 7, 2026 11:08
@Lee-W Lee-W merged commit 01b425a into apache:main Jul 8, 2026
288 of 289 checks passed
@Lee-W Lee-W deleted the validate-asset-event-partition-key branch July 8, 2026 01:53
@github-actions github-actions Bot added this to the Airflow 3.3.1 milestone Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.3.1 based on: backport label targeting v3-3-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-3-test PR Link

jason810496 added a commit to jason810496/airflow that referenced this pull request Jul 8, 2026
The wire schema gained an extra field on GetAssetEventByAsset and
GetAssetEventByAssetAlias in apache#69453 without the ts-sdk types being
regenerated. This PR's own changes to dev/breeze and the prek config
force a full static-checks run, where no hook is skipped, so the
check correctly surfaced that pre-existing drift and blocked CI.
jason810496 added a commit that referenced this pull request Jul 8, 2026
…69583)

* Make ts-sdk supervisor schema check a manual prek hook

CI's static-checks job runs `prek --all-files`, which runs every
default-stage hook against the whole repo tree regardless of what a
given PR actually touched. Because check-ts-sdk-supervisor-schema
lists task-sdk's schema.json as a trigger file, any task-sdk-only PR
that changes the wire schema fails static checks over an unrelated,
not-yet-regenerated ts-sdk file it never intended to touch.

Move the hook to the manual stage, matching how other on-demand
checks in this file (update-notice-year, upgrade-important-versions,
update-docker-gpg-keys) are handled: it stops gating unrelated PRs
and ts-sdk owners run it themselves (`prek run --hook-stage manual
check-ts-sdk-supervisor-schema`) when they pick up a schema change.

* Selectively skip ts-sdk supervisor schema check instead of manual stage

The first attempt made check-ts-sdk-supervisor-schema a manual-stage
hook, but review found that removes it from CI entirely (nothing
invokes it at the manual stage), so schema drift would merge
undetected.

Reuse the existing selective-skip mechanism already used for ktlint
and the mypy-* hooks instead: the hook keeps running in CI's default
static-checks sweep, but is now skipped when neither ts-sdk/ nor the
supervisor wire schema changed, so unrelated task-sdk-only PRs no
longer fail on it while real drift is still caught.

* Skip ts-sdk supervisor schema check unless ts-sdk itself changes

A task-sdk PR that bumps the supervisor wire schema should not be
responsible for regenerating the ts-sdk types - that is the ts-sdk
follow-up PR's job. Trigger the hook only on ts-sdk/ changes, both in
CI (selective skip) and locally (the hook's files pattern), so schema
authors are never blocked on a file they do not own. Drift merged via
a schema-only PR is still caught by full-tests runs (canary and
structural-change PRs run every hook) and by the next ts-sdk PR.

* Regenerate ts-sdk supervisor types for asset event extra fields

The wire schema gained an extra field on GetAssetEventByAsset and
GetAssetEventByAssetAlias in #69453 without the ts-sdk types being
regenerated. This PR's own changes to dev/breeze and the prek config
force a full static-checks run, where no hook is skipped, so the
check correctly surfaced that pre-existing drift and blocked CI.
Lee-W added a commit that referenced this pull request Jul 8, 2026
…API (#69453) (#69581)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Jul 9, 2026
…API (#69453) (#69581)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
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