ZhuLinsen/daily_stock_analysis · error · UnsupportedAlertTypeError

unsupported_alert_type

unsupported_alert_type

Error message

unsupported alert_type for Alert API: {alert_type or '<empty>'}

What it means

UnsupportedAlertTypeError (subclass of AlertServiceError, code unsupported_alert_type) raised in _normalize_rule_payload when alert_type — after lowercasing and stripping — is not in SUPPORTED_ALERT_TYPES (the union of symbol, portfolio, and market alert type sets). This runs before scope/type compatibility checks.

Source

Thrown at src/services/alert_service.py:881

        return {
            "items": [self._serialize_notification(row) for row in rows],
            "total": total,
            "page": page,
            "page_size": page_size,
        }

    def _normalize_rule_payload(self, payload: Dict[str, Any], *, source: str = "api") -> Dict[str, Any]:
        target_scope = str(payload.get("target_scope") or "single_symbol").strip()
        if target_scope not in SUPPORTED_TARGET_SCOPES:
            raise AlertServiceError(f"unsupported target_scope: {target_scope}")

        target = str(payload.get("target") or "").strip()
        if not target:
            raise AlertServiceError("target is required")

        alert_type = str(payload.get("alert_type") or "").strip().lower()
        if alert_type not in SUPPORTED_ALERT_TYPES:
            raise UnsupportedAlertTypeError(f"unsupported alert_type for Alert API: {alert_type or '<empty>'}")
        self._validate_scope_alert_type(target_scope, alert_type)

        severity = str(payload.get("severity") or "warning").strip().lower()
        if severity not in SUPPORTED_SEVERITIES:
            raise AlertServiceError(f"unsupported severity: {severity}")

        parameters = self._normalize_parameters(alert_type, payload.get("parameters") or {})
        target = self._normalize_target(target_scope, target)
        if target_scope == "single_symbol" and alert_type in LEGACY_RUNTIME_ALERT_TYPES:
            serialized_rule = {"stock_code": target, "alert_type": alert_type, **parameters}
            try:
                validate_event_alert_rule(serialized_rule)
            except ValueError as exc:
                raise AlertServiceError(str(exc)) from exc

        name = str(payload.get("name") or "").strip()
        if not name:
            name = self._default_rule_name(target=target, alert_type=alert_type, parameters=parameters)

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Check SUPPORTED_ALERT_TYPES in src/services/alert_service.py (line 77) for the exact set your backend accepts.
  2. Fix the spelling/casing — 'PRICE_CROSS' is fine (lowercased), 'price_crossing' is not.
  3. If the type is genuinely new, upgrade the backend first, then enable it in the client.

Example fix

// before
{"alert_type": "price_threshold", ...}

// after
{"alert_type": "price_cross", ...}
Defensive patterns

Strategy: type-guard

Validate before calling

from src.services.alert_service import SUPPORTED_ALERT_TYPES

alert_type = str(payload.get("alert_type") or "").strip().lower()
if alert_type not in SUPPORTED_ALERT_TYPES:
    raise HTTPException(status_code=400, detail=f"unsupported alert_type: {alert_type}")

Type guard

import { SUPPORTED_ALERT_TYPES } from "./alertTypes"; // keep in sync with backend
export function isSupportedAlertType(v: unknown): v is string {
  return typeof v === "string" && SUPPORTED_ALERT_TYPES.includes(v.toLowerCase());
}

Try / catch

from src.services.alert_service import AlertServiceError, UnsupportedAlertTypeError

try:
    alert_service.create_rule(payload)
except UnsupportedAlertTypeError as exc:
    return JSONResponse(status_code=422, content={"detail": str(exc)})

Prevention

When it happens

Trigger: Rule create/update with alert_type missing (message shows '<empty>'), misspelled ('price_crossing', 'volume-spike'), or a type the backend version does not support yet.

Common situations: Frontend deployed with new alert types ahead of the backend; typos in hand-written payloads; deprecated alert type renamed in a newer release; empty alert_type because the form default was never set.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/2f19150d74db5f51. Report an issue: GitHub.