[Fix] Key Expiry: return 400 for legacy -1 duration, fix Never Expires uncheck

- Return HTTP 400 with a clear migration message when duration="-1" is passed
  to the upperbound validation path, instead of crashing with an unhandled
  ValueError (500).
- Fix KeyLifecycleSettings: add else branch to handleNeverExpiresChange so
  unchecking "Never Expires" resets the form's duration field to undefined,
  preventing it from being submitted as null (never-expires).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
yuneng-jiang 2026-03-05 15:07:44 -08:00
parent 1a5a6e7999
commit 4b8b7bb557
2 changed files with 14 additions and 0 deletions

View file

@ -534,6 +534,13 @@ async def _common_key_generation_helper( # noqa: PLR0915
upperbound_duration = duration_in_seconds(
duration=upperbound_value
)
if value == "-1":
raise HTTPException(
status_code=400,
detail={
"error": "'-1' is no longer a valid duration value. Pass duration: null to set a key to never expire."
},
)
user_duration = duration_in_seconds(duration=value)
if user_duration > upperbound_duration:
raise HTTPException(

View file

@ -69,6 +69,13 @@ const KeyLifecycleSettings: React.FC<KeyLifecycleSettingsProps> = ({
} else if (form && typeof form.setFieldsValue === "function") {
form.setFieldsValue({ duration: null });
}
} else {
// Clear the null so duration is omitted from the request (not sent as never-expires)
if (form && typeof form.setFieldValue === "function") {
form.setFieldValue("duration", undefined);
} else if (form && typeof form.setFieldsValue === "function") {
form.setFieldsValue({ duration: undefined });
}
}
};