Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(scale): normalize backend nulls before they reach the policy form

Juan Denis2c7f13051f75
diff --git a/frontend/src/components/apps/__tests__/autoScalePolicy.test.mjs b/frontend/src/components/apps/__tests__/autoScalePolicy.test.mjs
index 61d2ab66..34afafb9 100644
--- a/frontend/src/components/apps/__tests__/autoScalePolicy.test.mjs
+++ b/frontend/src/components/apps/__tests__/autoScalePolicy.test.mjs
@@ -18,6 +18,18 @@ test('normalizes a missing policy to the UI defaults', () => {
});
});
+test('coerces backend nulls back to form-safe values', () => {
+ // The backend stores an unset service_name as null; the form must never
+ // receive it or the inputs flip from controlled to uncontrolled.
+ assert.deepEqual(normalizeScalePolicy({
+ enabled: null,
+ service_name: null,
+ min_replicas: null,
+ max_replicas: 'not-a-number',
+ current_replicas: null,
+ }), DEFAULT_SCALE_POLICY);
+});
+
test('serializes the policy using the same bounds as the API', () => {
assert.deepEqual(scalePolicyPayload({
enabled: true,
diff --git a/frontend/src/components/apps/autoScalePolicy.js b/frontend/src/components/apps/autoScalePolicy.js
index 6d80da0a..ae7153cd 100644
--- a/frontend/src/components/apps/autoScalePolicy.js
+++ b/frontend/src/components/apps/autoScalePolicy.js
@@ -19,7 +19,20 @@ function percentage(value, fallback) {
}
export function normalizeScalePolicy(data) {
- return { ...DEFAULT_SCALE_POLICY, ...(data || {}) };
+ // The backend stores an unset service_name as null; coerce it (and any
+ // non-numeric counters) back to form-safe values so inputs stay controlled.
+ const merged = { ...DEFAULT_SCALE_POLICY, ...(data || {}) };
+ return {
+ ...merged,
+ enabled: !!merged.enabled,
+ service_name: typeof merged.service_name === 'string' ? merged.service_name : '',
+ min_replicas: integerOr(merged.min_replicas, DEFAULT_SCALE_POLICY.min_replicas),
+ max_replicas: integerOr(merged.max_replicas, DEFAULT_SCALE_POLICY.max_replicas),
+ cpu_high_percent: integerOr(merged.cpu_high_percent, DEFAULT_SCALE_POLICY.cpu_high_percent),
+ cpu_low_percent: integerOr(merged.cpu_low_percent, DEFAULT_SCALE_POLICY.cpu_low_percent),
+ cooldown_seconds: integerOr(merged.cooldown_seconds, DEFAULT_SCALE_POLICY.cooldown_seconds),
+ current_replicas: integerOr(merged.current_replicas, DEFAULT_SCALE_POLICY.current_replicas),
+ };
}
export function scalePolicyPayload(form) {