Skip to content

Reject unknown update_mask fields instead of silently ignoring them - #71003

Closed
ColtenOuO wants to merge 3 commits into
apache:mainfrom
ColtenOuO:api-reject-unknown-update-mask
Closed

ColtenOuO wants to merge 3 commits into
apache:mainfrom
ColtenOuO:api-reject-unknown-update-mask

Conversation

@ColtenOuO

@ColtenOuO ColtenOuO commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

update_mask lets a PATCH caller say "only apply these fields". Every endpoint implements it by intersecting the mask with the fields present in the body:

fields_to_update = patch_body.model_fields_set.intersection(update_mask)

An entry that matches no field simply falls out of the intersection. Nothing notices, so the request becomes a no-op and still answers 200, echoing back the untouched record. A typo is indistinguishable from success:

$ curl -X PATCH '.../variables/pk?update_mask=value' -d '{"key":"pk","value":"CHANGED",...}'
200   # value -> "CHANGED"

$ curl -X PATCH '.../variables/pk?update_mask=valu' -d '{"key":"pk","value":"CHANGED",...}'
200   # value still "original"

$ curl -X PATCH '.../pools/p?update_mask=slot' -d '{"pool":"p","slots":99,...}'
200   # slots still 1

A stray space does the same, since nothing trims the entries (update_mask=%20value). A client that checks the status code has no way to learn its patch never landed.

dags.py already guards against this (if update_mask != ["is_paused"]: raise 400), so rejecting an unusable mask is an established expectation in this API. It was just missing everywhere else that accepts one.

Before / after

Request Before After
?update_mask=value 200, applied unchanged
?update_mask=valu 200, not applied 400 naming the unknown field
?update_mask=%20value 200, not applied 200, applied
bulk PATCH with "update_mask": ["valu"] 200, not applied 200, error in that action's errors

The error names both the offender and the accepted fields:

Unknown field(s) in update_mask: 'slot'.
Valid fields are: description, include_deferred, name, slots, team_name.

The change

  • update_mask_param_factory(body_type) in common/parameters.py builds a validated update_mask query parameter. The single-entity PATCH routes take it through Depends: variables, pools, connections, dag runs, and the task-instance patch, dry_run and task-group routes. dags.py is left alone because it already validates.
  • Bulk endpoints carry the mask in the request body, so BulkService.handle_request validates it per update action. A bad mask is reported in that action's errors with status_code: 400, and the other actions still run. This matches how bulk already reports a missing entity or an immutable field.

Two decisions worth flagging:

Field names and validation aliases are accepted, serialization aliases are not. ConnectionBody.schema_ is aliased to schema, and update_mask=["schema","extra"] is a working request today, so input aliases must pass. A serialization-only alias is an output name the body can never carry. Accepting it would let update_mask=val on a variable (VariableBody.value serializes as val) through validation as a silent no-op.

Whitespace is trimmed rather than rejected. pools.py already compares with mask.strip(), and the intent of " value" is not in doubt.

Note on an existing test

test_patch_dag_run_with_update_mask had a case asserting that {"update_mask": ["random"]} returns 200, which recorded the buggy behaviour as an expectation. It now expects 400 and the error message.

Tests

Each route wires the dependency on its own line, so every endpoint that takes a mask has a 400 case:

  • variables: a typo, a name that exists nowhere, an empty string and the serialization alias val return 400 and leave the row unchanged; a mask with surrounding whitespace still applies
  • pools, connections: 400 and the stored value is unchanged
  • task instances: patch, dry_run and task-group routes return 400 without setting any state
  • dag runs: the corrected case above
  • bulk variables: 200, with the error in update.errors and the row unchanged

test_variables, test_pools, test_connections, TestPatchDagRun and the new task-instance test: 361 passed.


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

Generated-by: Claude Code (Opus 5) following the guidelines

@boring-cyborg boring-cyborg Bot added the area:API Airflow's REST/HTTP API label Aug 3, 2026
@ColtenOuO
ColtenOuO force-pushed the api-reject-unknown-update-mask branch from c6c2495 to 8344c90 Compare August 3, 2026 17:41
@potiuk
potiuk marked this pull request as draft August 13, 2026 13:00
@ColtenOuO
ColtenOuO force-pushed the api-reject-unknown-update-mask branch from 8344c90 to b3ebc60 Compare August 13, 2026 18:35
@ColtenOuO

Copy link
Copy Markdown
Contributor Author

Resolve the merge conflict and re-run the CI.

@ColtenOuO
ColtenOuO marked this pull request as ready for review August 14, 2026 02:31

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

Thanks for the PR.

Just one small refactoring suggestion

@pierrejeambrun

Copy link
Copy Markdown
Member

Also worth a small significant newsfragment, to warn users that these endpoints will now 'error' on wrong payload instead of silently '200'.

@ColtenOuO
ColtenOuO force-pushed the api-reject-unknown-update-mask branch from b3ebc60 to 6f38b51 Compare August 28, 2026 14:44
@ColtenOuO

Copy link
Copy Markdown
Contributor Author

addressed feedback and added newsfragment.

@Andrushika Andrushika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! the direction makes sense to me.

Left three comments: one on the alias set, one on the bulk error shape, one on test coverage.

Review feedback: the check belongs with the other query parameters in
parameters.py, so a route declares it once instead of every route and
service calling a validator by hand. Bulk endpoints carry the mask in the
request body rather than the query string, so they keep a single check --
now up front, before any entity is written, instead of part way through
the loop.
@ColtenOuO
ColtenOuO force-pushed the api-reject-unknown-update-mask branch from ba8347b to 86ae3ed Compare September 19, 2026 17:43

@Andrushika Andrushika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM after fix, thanks!
We should also mention some more affected endpoints in newfragment.

A bad mask on a bulk PATCH failed the whole request with 400, while every
other per-action failure (a missing entity, an immutable field) is reported
in that action's errors and the rest of the request still applies. Bulk
clients now get one error shape for all of them.

Serialization aliases were accepted as mask entries although a request body
can never carry them, so update_mask=val on a variable passed validation and
still updated nothing -- the silent no-op this change exists to remove. Only
field names and validation aliases are accepted now.

Each route wires the validated update_mask dependency on its own line, so a
400 case is added for every endpoint that takes a mask; dropping the wiring
from any one of them now fails a test.
@ColtenOuO
ColtenOuO force-pushed the api-reject-unknown-update-mask branch from 86ae3ed to cec46f5 Compare September 24, 2026 03:43

@Andrushika Andrushika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!!

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

After second though, I'm afraid this could break some workflow.

Since this isn't critical and other query params work like this (typo in filter or adding extra unknown query parameters will just be ignored without 400ing) I'd lean on not merging this at this point.

I'll close this for now. Feel free to re-open if you want to convert this into a 'warning' instead, without altering the current behavior.

(Also in the current implementation I believe aliased field + bulk TI endpoints are not properly handled)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants