{"record":{"id":"18240deb82c4a855","repo":"HKUDS/Vibe-Trading","slug":"field-name-must-be-a-date-datetime-or-iso-8601","errorCode":null,"errorMessage":"{field_name} must be a date, datetime, or ISO-8601 string, got {type(value).__name__}","messagePattern":"(.+?) must be a date, datetime, or ISO-8601 string, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/models.py","lineNumber":135,"sourceCode":"        return value.date()\n    if isinstance(value, date):\n        return value\n    if isinstance(value, str):\n        text = value.strip()\n        if not text:\n            raise ValueError(f\"{field_name} is required and cannot be empty\")\n        try:\n            return date.fromisoformat(text)\n        except ValueError:\n            pass\n        try:\n            return datetime.fromisoformat(text).date()\n        except ValueError as exc:\n            raise ValueError(\n                f\"{field_name}={value!r} is not ISO-8601 (YYYY-MM-DD); pass an \"\n                \"explicit date_format instead of relying on inference\"\n            ) from exc\n    raise ValueError(\n        f\"{field_name} must be a date, datetime, or ISO-8601 string, \"\n        f\"got {type(value).__name__}\"\n    )\n\n\n@dataclass(frozen=True)\nclass Entity:\n    \"\"\"A legal entity that issues, manages, or faces an instrument.\n\n    Attributes:\n        entity_id: Stable identifier, e.g. an LEI, a CIK, or a local key.\n        name: Human-readable legal name.\n        entity_type: Role the entity plays; see ``EntityType``.\n        domicile: Country or jurisdiction code, free-form and optional.\n        parent_id: ``entity_id`` of the parent entity, when part of a group.\n    \"\"\"\n\n    entity_id: str","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/models.py#L117-L153","documentation":"normalize_date only accepts date, datetime, or str inputs; any other type (int, None, pandas.Timestamp subclass edge cases aside) raises ValueError naming the field and actual type.","triggerScenarios":"Passing date=None, date=20240331 (int), or a numpy datetime64 to a model constructor or date-taking function.","commonSituations":"Untyped data from APIs/dicts where the date field is null, or serial dates from Excel feeds.","solutions":["Convert to date first: pd.to_datetime(v).date()","Guard None: skip or default the record when the field is missing","Add a type check/validation layer at ingestion"],"exampleFix":"# before\nEntityLevel(date=row['dt'], ...)\n# after\nfrom datetime import date\nEntityLevel(date=date.fromtimestamp(row['dt']), ...)  # or convert appropriately","handlingStrategy":"type-guard","validationCode":"from datetime import date, datetime\nif not isinstance(d, (date, datetime, str)): d = convert(d)","typeGuard":"def is_date_like(v) -> bool: return isinstance(v, (date, datetime, str))","tryCatchPattern":"except ValueError as e:\n    if 'must be a date' in str(e): convert value to datetime.date and retry","preventionTips":["Convert numpy/Excel serials to date before passing","Null-check date fields from JSON"],"tags":["validation","date","type-error","models"],"backgroundTag":"type-validation-failed","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}