Handle undecryptable Variable values gracefully in Stable REST API#65452
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
|
This is far too little for a PR. This one needs to: a) explain in the code (not only in PR) we are doing it in the code |
|
Behavior change Before: GET /variables/{key} returned HTTP 500 with an OpenAPI validation error when the stored value could not be decrypted. After: The same endpoint returns HTTP 200 with "value": null, matching what the list endpoint already did. Compatibility
|
|
@shan-zeeshan786 Converting to draft — this PR doesn't yet meet our Pull Request quality criteria.
See the linked criteria for how to fix each item, then mark the PR "Ready for review". This is not a rejection — just an invitation to bring the PR up to standard. No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
dc9033c to
a04ad3d
Compare
…t mock, regenerate openapi spec + UI/airflowctl datamodels
…rate openapi/airflowctl datamodels, single-line newsfragment, real fernet decrypt mock
|
Why is it targetting v3-2-test and not main @shan-zeeshan786 ? Can you explain please. I will convert it to draft until this is explained. Usually we fix things in main and cherry-pick - see contrib guides |
|
In one of my PR @pierrejeambrun suggested to target *-test branch that's why i changed it to test instead of main @potiuk. Here also, lots of CI were failing.
|
code, add a regression test, and add newsfragment 65452.bugfix.rst
…t mock, regenerate openapi spec + UI/airflowctl datamodels
…rate openapi/airflowctl datamodels, single-line newsfragment, real fernet decrypt mock
a7148be to
bc5ff80
Compare
That's because you were targeting airflow 2.x, so latest v2-x-test branch is the appropriate one. Here if you target airflow 3.x it's handled differently. We always merge to main. Then people merging or the release manager will handle backporting to the appropriate minor version branch (v3-2-test) if needed. |
Thank you for the clarification, @pierrejeambrun. I had already updated the target branch to main at that time. Could you please review and validate this PR when convenient? |
pierrejeambrun
left a comment
There was a problem hiding this comment.
LGTM, just a few suggestion before we can merge.
@potiuk If you mind taking another look and reconsider your 'request for change' it would be great.
Removed all extra comments, suggested by @pierrejeambrun. |
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
Backport successfully created: v3-2-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
… REST API (#65452) (#67828) * Allow null values for Variable value field to handle decryption failures gracefully * Document rationale in code, add a regression test, and add newsfragment 65452.bugfix.rst * Fix CI for #65452: single-line newsfragment, real fernet decrypt mock, regenerate openapi spec + UI/airflowctl datamodels * Fix CI for #65452: handle nullable Variable.value in UI, regenerate openapi/airflowctl datamodels, single-line newsfragment, real fernet decrypt mock * Removed all the comments, suggested by the reviewers --------- (cherry picked from commit f4cc43d) Co-authored-by: Md Zeeshan alam <93471402+shan-zeeshan786@users.noreply.github.com> Co-authored-by: Md Zeeshan Alam <zeeshan@Mds-MacBook-Air.local>


Fix Variables API returning 500 for undecryptable values
What is the problem?
When a Fernet key is rotated or misconfigured, previously stored encrypted Variable values may become undecryptable.
Calling:
GET /api/v1/variables/{key}
result in a 500 Internal Server Error with a schema validation message
While calling list varibales
GET /api/v2/variables
returns the variables successfully, but with values as null when decryption fails.
List api output:
{
"total_entries": 1,
"variables": [
{
"description": "Testing variable use",
"key": "Testing",
"value": null
}
]
}
GET variable Response:
{
"detail": "None is not of type 'string'\n\nFailed validating 'type' in schema['allOf'][1]['properties']['value']:\n{'type': 'string'}\n\nOn instance['value']:\n None",
"status": 500,
"title": "Response body does not conform to specification",
"type": "https://airflow.apache.org/docs/apache-airflow/3.2.0/stable-rest-api-ref.html#section/Errors/Unknown"
}
This occurs because the decrypted value becomes None, which violates the OpenAPI schema expecting a string and inconsistent and confusing API behavior.
Expected output:
{
"description": "Testing variable use",
"key": "Testing",
"value": null
}
Why is this change needed?
What is changed?
The value field in the Variables API response schema has been updated to handle undecryptable values safely:
val: str = Field(alias="value")
val: str | None = Field(alias="value", default=None)
Why this change?
Related issue
open: #65391