From d1422f295b0b7655f4ceeda59b987219a44ba08b Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Fri, 6 Feb 2026 09:34:10 -0600 Subject: [PATCH] don't save model config back to yaml when saving detectors --- .../config-form/section-configs/detectors.ts | 1 - .../sections/section-special-cases.ts | 21 +++++++++++++++++++ .../theme/fields/DetectorHardwareField.tsx | 13 ++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/web/src/components/config-form/section-configs/detectors.ts b/web/src/components/config-form/section-configs/detectors.ts index 02bdecd95..3ca2dd81d 100644 --- a/web/src/components/config-form/section-configs/detectors.ts +++ b/web/src/components/config-form/section-configs/detectors.ts @@ -10,7 +10,6 @@ const detectorHiddenFields = [ const detectors: SectionConfigOverrides = { base: { sectionDocs: "/configuration/object_detectors", - restartRequired: [], fieldOrder: [], advancedFields: [], hiddenFields: detectorHiddenFields, diff --git a/web/src/components/config-form/sections/section-special-cases.ts b/web/src/components/config-form/sections/section-special-cases.ts index 7a882a5c3..1f4b9ddae 100644 --- a/web/src/components/config-form/sections/section-special-cases.ts +++ b/web/src/components/config-form/sections/section-special-cases.ts @@ -146,5 +146,26 @@ export function sanitizeOverridesForSection( }; } + // detectors: Strip readonly model fields that are generated on startup + // and should never be persisted back to the config file. + if (sectionPath === "detectors") { + const overridesObj = overrides as JsonObject; + const cleaned: JsonObject = {}; + + Object.entries(overridesObj).forEach(([key, value]) => { + if (!isJsonObject(value)) { + cleaned[key] = value; + return; + } + + const cleanedValue = { ...value } as JsonObject; + delete cleanedValue.model; + delete cleanedValue.model_path; + cleaned[key] = cleanedValue; + }); + + return cleaned; + } + return overrides; } diff --git a/web/src/components/config-form/theme/fields/DetectorHardwareField.tsx b/web/src/components/config-form/theme/fields/DetectorHardwareField.tsx index 2a38c70e6..3eab4fdb3 100644 --- a/web/src/components/config-form/theme/fields/DetectorHardwareField.tsx +++ b/web/src/components/config-form/theme/fields/DetectorHardwareField.tsx @@ -6,6 +6,7 @@ import type { UiSchema, } from "@rjsf/utils"; import { toFieldPathId } from "@rjsf/utils"; +import { cloneDeep, set as lodashSet } from "lodash"; import { useCallback, useEffect, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { @@ -297,8 +298,8 @@ export function DetectorHardwareField(props: FieldProps) { }, [detectors]); const updateDetectors = useCallback( - (nextDetectors: JsonObject) => { - onChange(nextDetectors as unknown, [] as FieldPathList); + (nextDetectors: JsonObject, path?: FieldPathList) => { + onChange(nextDetectors as unknown, path ?? ([] as FieldPathList)); }, [onChange], ); @@ -562,14 +563,12 @@ export function DetectorHardwareField(props: FieldProps) { const handleInstanceChange = ( nextValue: unknown, - _path: FieldPathList, + path: FieldPathList, _errors?: ErrorSchema, _id?: string, ) => { - const nextDetectors = { - ...detectors, - [key]: nextValue ?? {}, - } as JsonObject; + const nextDetectors = cloneDeep(detectors); + lodashSet(nextDetectors, path, nextValue); updateDetectors(nextDetectors); };