{"record":{"id":"c33b675d6d7ed4c7","repo":"HKUDS/Vibe-Trading","slug":"unknown-security-type-self-security-type-r-expe","errorCode":null,"errorMessage":"unknown security_type {self.security_type!r}; expected one of: {valid}","messagePattern":"unknown security_type (.+?); expected one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/models.py","lineNumber":261,"sourceCode":"\n    def __post_init__(self) -> None:\n        \"\"\"Validate the base fields and coerce ``security_type``.\n\n        Raises:\n            ValueError: If ``security_type`` is not a known member.\n        \"\"\"\n        super().__post_init__()\n        object.__setattr__(self, \"symbol\", self.symbol.strip() if self.symbol else \"\")\n        object.__setattr__(\n            self, \"exchange\", self.exchange.strip() if self.exchange else \"\"\n        )\n        try:\n            object.__setattr__(\n                self, \"security_type\", SecurityType(self.security_type)\n            )\n        except ValueError as exc:\n            valid = \", \".join(member.value for member in SecurityType)\n            raise ValueError(\n                f\"unknown security_type {self.security_type!r}; \"\n                f\"expected one of: {valid}\"\n            ) from exc\n\n\n@dataclass(frozen=True)\nclass Fund(Instrument):\n    \"\"\"A pooled vehicle whose economics are calls, distributions, and NAV marks.\n\n    This is the archetypal instrument that cannot be expressed as a daily bar:\n    a closed-end fund has no price, only an irregular cash-flow stream and a\n    periodic valuation.\n\n    Attributes:\n        vintage_year: Year the fund began investing, when known.\n        structure: Capital structure; see ``FundStructure``.\n        strategy: Free-form strategy label, e.g. ``\"buyout\"``.\n        commitment: Total capital committed by the holder, in ``currency``.","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/models.py#L243-L279","documentation":"Security.__post_init__ coerces security_type through the SecurityType enum; unknown strings raise ValueError with the list of valid values. The match is exact against enum member values.","triggerScenarios":"Security(instrument_id='x', security_type='Common Stock') with case mismatch, trailing whitespace, or a label not in SecurityType (e.g. 'etf' when only 'ETF' or 'fund' are defined).","commonSituations":"Mapping vendor security type codes (e.g. 'CS', 'EQ') directly to the field without a translation table; free-text type columns in reference data; enum members added/renamed across versions while persisted records keep old labels.","solutions":["Pass an exact SecurityType member or its .value","Build an alias/normalization map (strip, upper/lower, vendor codes) before constructing Security objects","When the type is genuinely new, extend the SecurityType enum rather than bypassing validation"],"exampleFix":"# before\nSecurity(instrument_id='a', security_type='common stock')\n\n# after\nSecurity(instrument_id='a', security_type=SecurityType.COMMON_STOCK.value)","handlingStrategy":"validation","validationCode":"from agent.src.entities.models import SecurityType\nvalid = {m.value for m in SecurityType}\nst = row['security_type'].strip()\nif st not in valid:\n    st = ALIAS_MAP.get(st.lower(), st)\nassert st in valid, f\"bad security_type {st!r}\"","typeGuard":"from agent.src.entities.models import SecurityType\n\ndef is_valid_security_type(v: str) -> bool:\n    try:\n        SecurityType(v)\n        return True\n    except ValueError:\n        return False","tryCatchPattern":"try:\n    s = Security(instrument_id=iid, security_type=st, ...)\nexcept ValueError as exc:\n    if 'unknown security_type' in str(exc):\n        log.warning('quarantining row with bad security_type %r', st)\n        continue\n    raise","preventionTips":["Translate vendor codes to SecurityType values at the ingest boundary","Use enum members, not hand-typed strings, in code","Add regression tests when enum members are renamed"],"tags":["python","dataclass","enum-validation","securities"],"backgroundTag":"enum-value-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}