Repository navigation
Stop airflowctl from failing on fields added by newer API servers - #75610
Conversation
Seven core API models that only appear in responses, the config models and the asset reference models, extend StrictBaseModel. So the OpenAPI spec marks them "additionalProperties: false", and the airflowctl models generated from it get extra="forbid". When a newer server adds a field to one of them, an older airflowctl fails to parse the response. apache#71446 added the optional team_name field to two asset reference models for 3.4, and airflowctl from airflow-ctl/v0-1-test now fails on "assets list" and "assets get" against 3.4.0b2. StrictBaseModel is meant for request bodies, so that unknown fields sent by a client are rejected (apache#44306). Response models are built by the server, and new fields in them should not break existing clients.
|
cc @shahar1 :) |
shahar1
left a comment
There was a problem hiding this comment.
LGTM. The fix is correct and minimal: I checked the generated spec on main, and these seven are exactly the additionalProperties: false schemas that are reachable only from responses, with no strict schema shared between a request body and a response. The three new airflowctl tests fail with extra_forbidden on the base and pass with the change, and CI is green.
Smaller observations
airflow-core/src/airflow/api_fastapi/core_api/base.py:39— Optional, not blocking. The root cause here is that seven response-only models pickedStrictBaseModel. Its docstring says to use it for models that "should not have any extra fields in the payload", which reads as applying to responses too. A one-line note there that it is for request bodies only, becauseadditionalProperties: falsein the spec makes generated clients such as airflowctl reject fields that newer servers add, would record the constraint this PR relies on and make the next response model less likely to repeat it. The file is not in the diff, so this can also go in a follow-up.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Airflow handles maintainer review:
Contributing guide.
Backport failed to create: airflow-ctl/v0-1-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker e990430 airflow-ctl/v0-1-testThis should apply the commit to the airflow-ctl/v0-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
…by newer API servers (#75610) (#75754) Seven core API models that only appear in responses, the config models and the asset reference models, extend StrictBaseModel. So the OpenAPI spec marks them "additionalProperties: false", and the airflowctl models generated from it get extra="forbid". When a newer server adds a field to one of them, an older airflowctl fails to parse the response. #71446 added the optional team_name field to two asset reference models for 3.4, and airflowctl from airflow-ctl/v0-1-test now fails on "assets list" and "assets get" against 3.4.0b2. StrictBaseModel is meant for request bodies, so that unknown fields sent by a client are rejected (#44306). Response models are built by the server, and new fields in them should not break existing clients. (cherry picked from commit e990430)
The seven response models that moved back to BaseModel in #75610 had picked StrictBaseModel because its docstring reads as a general recommendation: use it where extra fields should not be accepted. Nothing at the class recorded why that is limited to request bodies. A response model is instantiated from a source object that holds more than it returns, so forbidding extra fields rejects its own construction; and the setting reaches generated clients as additionalProperties: false, so an older airflowctl rejects a field a newer server adds. The second reason is what #75610 had to fix, and neither was written down where the next response model would look.
…by newer API servers (#75610) (#75754) Seven core API models that only appear in responses, the config models and the asset reference models, extend StrictBaseModel. So the OpenAPI spec marks them "additionalProperties: false", and the airflowctl models generated from it get extra="forbid". When a newer server adds a field to one of them, an older airflowctl fails to parse the response. #71446 added the optional team_name field to two asset reference models for 3.4, and airflowctl from airflow-ctl/v0-1-test now fails on "assets list" and "assets get" against 3.4.0b2. StrictBaseModel is meant for request bodies, so that unknown fields sent by a client are rejected (#44306). Response models are built by the server, and new fields in them should not break existing clients. (cherry picked from commit e990430)
Why
airflowctl generates its API models from the core OpenAPI spec.
In core,
StrictBaseModelrejects unknown fields. The spec shows this asadditionalProperties: false. airflowctl then generates the same model withextra="forbid".#44306 added
StrictBaseModelfor request bodies only. Response models do not reject extra fields:Seven core models extend
StrictBaseModel, but they only appear in responses. They are the three config models and the four asset reference models. If a newer server adds a field to one of them, an older airflowctl cannot read the response.This happens now. #71446 added the optional
team_namefield to two of these models in 3.4. airflowctl fromairflow-ctl/v0-1-testfails onassets listandassets getagainst 3.4.0b2 (#57826).What
The seven models now extend
BaseModel. The spec, the UI schemas and the airflowctl models are regenerated. The server sends the same JSON as before.With the same change on
airflow-ctl/v0-1-test, the 3.4.0b2 runs pass again. A backport for 0.1.6 must include the two core files, because that branch generates its models from its own core.related: #57826
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines