feat(mm): better errors when invalid model config found in db

This commit is contained in:
psychedelicious
2025-09-23 18:26:57 +10:00
parent b7491b700f
commit 424b2deb5c

View File

@@ -292,14 +292,19 @@ class ModelRecordServiceSQL(ModelRecordServiceBase):
for row in result:
try:
model_config = ModelConfigFactory.make_config(json.loads(row[0]), timestamp=row[1])
except pydantic.ValidationError:
except pydantic.ValidationError as e:
# We catch this error so that the app can still run if there are invalid model configs in the database.
# One reason that an invalid model config might be in the database is if someone had to rollback from a
# newer version of the app that added a new model type.
row_data = f"{row[0][:64]}..." if len(row[0]) > 64 else row[0]
try:
name = json.loads(row[0]).get("name", "<unknown>")
except Exception:
name = "<unknown>"
self._logger.warning(
f"Found an invalid model config in the database. Ignoring this model. ({row_data})"
f"Skipping invalid model config in the database with name {name}. Ignoring this model. ({row_data})"
)
self._logger.warning(f"Validation error: {e}")
else:
results.append(model_config)