fix: return disabled auto-upgrade settings when strategy is missing (#39494)

This commit is contained in:
非法操作 2026-07-24 14:15:02 +08:00 committed by GitHub
parent 3ab9e083e0
commit aef1c67721
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 8 deletions

View File

@ -442,12 +442,10 @@ register_enum_models(
)
def _default_auto_upgrade_settings(
tenant_id: str,
category: TenantPluginAutoUpgradeCategory,
) -> AutoUpgradeSettingsResponse:
def _missing_auto_upgrade_settings(tenant_id: str) -> AutoUpgradeSettingsResponse:
"""Represent a missing persisted strategy as effectively disabled."""
return {
"strategy_setting": PluginAutoUpgradeService.default_strategy_setting_for_category(category),
"strategy_setting": TenantPluginAutoUpgradeStrategySetting.DISABLED,
"upgrade_time_of_day": PluginAutoUpgradeService.default_upgrade_time_of_day(tenant_id),
"upgrade_mode": TenantPluginAutoUpgradeMode.EXCLUDE,
"exclude_plugins": [],
@ -1135,9 +1133,7 @@ class PluginFetchAutoUpgradeApi(Resource):
args = ParserAutoUpgradeFetch.model_validate(request.args.to_dict(flat=True))
auto_upgrade = PluginAutoUpgradeService.get_strategy(tenant_id, args.category, session=db.session())
auto_upgrade_dict = (
_auto_upgrade_settings_to_dict(auto_upgrade)
if auto_upgrade
else _default_auto_upgrade_settings(tenant_id, args.category)
_auto_upgrade_settings_to_dict(auto_upgrade) if auto_upgrade else _missing_auto_upgrade_settings(tenant_id)
)
return jsonable_encoder(

View File

@ -1343,6 +1343,34 @@ class TestPluginFetchAutoUpgradeApi:
assert result["category"] == TenantPluginAutoUpgradeCategory.TOOL
assert result["auto_upgrade"]["upgrade_time_of_day"] == 1
def test_returns_disabled_settings_when_strategy_is_missing(self, app: Flask):
api = PluginFetchAutoUpgradeApi()
method = unwrap(api.get)
with (
app.test_request_context(f"/?category={TenantPluginAutoUpgradeCategory.MODEL.value}"),
patch(
"controllers.console.workspace.plugin.PluginAutoUpgradeService.get_strategy",
return_value=None,
),
patch(
"controllers.console.workspace.plugin.PluginAutoUpgradeService.default_upgrade_time_of_day",
return_value=78300,
),
):
result = method(api, "t1")
assert result == {
"category": TenantPluginAutoUpgradeCategory.MODEL,
"auto_upgrade": {
"strategy_setting": TenantPluginAutoUpgradeStrategySetting.DISABLED,
"upgrade_time_of_day": 78300,
"upgrade_mode": TenantPluginAutoUpgradeMode.EXCLUDE,
"exclude_plugins": [],
"include_plugins": [],
},
}
class TestPluginAutoUpgradeExcludePluginApi:
def test_success(self, app: Flask):