{"record":{"id":"75d3e91ba44bf369","repo":"HKUDS/Vibe-Trading","slug":"unknown-entity-type-self-entity-type-r-expected","errorCode":null,"errorMessage":"unknown entity_type {self.entity_type!r}; expected one of: {valid}","messagePattern":"unknown entity_type (.+?); expected one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/models.py","lineNumber":174,"sourceCode":"    domicile: str = \"\"\n    parent_id: str | None = None\n\n    def __post_init__(self) -> None:\n        \"\"\"Validate identifiers and coerce ``entity_type`` to its enum member.\n\n        Raises:\n            ValueError: If ``entity_id`` is blank or ``entity_type`` is unknown.\n        \"\"\"\n        cleaned = self.entity_id.strip() if isinstance(self.entity_id, str) else \"\"\n        if not cleaned:\n            raise ValueError(\"entity_id is required and cannot be empty\")\n        object.__setattr__(self, \"entity_id\", cleaned)\n        object.__setattr__(self, \"name\", self.name.strip() if self.name else \"\")\n        try:\n            object.__setattr__(self, \"entity_type\", EntityType(self.entity_type))\n        except ValueError as exc:\n            valid = \", \".join(member.value for member in EntityType)\n            raise ValueError(\n                f\"unknown entity_type {self.entity_type!r}; expected one of: {valid}\"\n            ) from exc\n        if self.parent_id is not None and self.parent_id == self.entity_id:\n            raise ValueError(f\"entity {self.entity_id!r} cannot be its own parent\")\n\n\n@dataclass(frozen=True)\nclass Instrument:\n    \"\"\"Base class for anything that can be held and analysed.\n\n    Subclasses add asset-class specifics; they may only add fields *with*\n    defaults, because the base already declares defaulted fields.\n\n    Attributes:\n        instrument_id: Stable identifier, e.g. an ISIN, a ticker, or a local key.\n        currency: Required ISO-style currency code of this instrument's cash\n            flows. Normalized to uppercase.\n        name: Human-readable name.","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/models.py#L156-L192","documentation":"Raised by Entity.__post_init__ when the entity_type string cannot be matched to a member of the EntityType enum. The constructor coerces entity_type via EntityType(self.entity_type), so any value outside the enum's allowed values (including wrong case, whitespace, or typos) fails. The message lists all valid values.","triggerScenarios":"Constructing an Entity (or subclass) with entity_type='organisation', 'Trust', ' fund', or any string not exactly matching an EntityType member value. The enum lookup is exact, so case or whitespace differences reject values that were stripped for other fields but not for entity_type.","commonSituations":"Loading entities from CSV/JSON/user input where type labels are free text; renaming or adding enum members between versions while stale records still carry old labels; passing a display-case label ('Company') instead of the stored value ('company').","solutions":["Pass an exact EntityType member value, e.g. EntityType.COMPANY.value, or the enum member itself","Normalize input before construction: entity_type.strip().lower() and map aliases to canonical enum values","If loading legacy data, build an alias map and translate unknown labels, surfacing a per-row error report instead of failing hard"],"exampleFix":"// before\nEntity(entity_id='e1', entity_type='Company')\n\n# after\nEntity(entity_id='e1', entity_type=EntityType.COMPANY.value)","handlingStrategy":"validation","validationCode":"from agent.src.entities.models import Entity, EntityType\nvalid = {m.value for m in EntityType}\nraw = row['entity_type'].strip().lower()\nif raw not in valid:\n    raise KeyError(f\"unknown entity_type {raw!r}; valid: {sorted(valid)}\")","typeGuard":"from agent.src.entities.models import EntityType\n\ndef is_valid_entity_type(v: str) -> bool:\n    try:\n        EntityType(v)\n        return True\n    except ValueError:\n        return False","tryCatchPattern":"try:\n    e = Entity(entity_id=iid, entity_type=raw)\nexcept ValueError as exc:\n    if 'unknown entity_type' in str(exc):\n        log.warning('skipping row with bad entity_type: %r', raw)\n        continue\n    raise","preventionTips":["Resolve entity_type to an EntityType member at the edge of your system","Keep an alias map for legacy/free-text labels","Reject or quarantine rows failing enum validation instead of guessing"],"tags":["python","dataclass","enum-validation","entities"],"backgroundTag":"enum-value-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}