{"record":{"id":"9a96dde39d16aa49","repo":"hsliuping/TradingAgents-CN","slug":"6","errorCode":null,"errorMessage":"股票代码必须是6位数字","messagePattern":"股票代码必须是6位数字","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tradingagents/models/stock_data_models.py","lineNumber":95,"sourceCode":"    board: str = Field(..., description=\"板块\")\n    industry: str = Field(..., description=\"行业\")\n    industry_code: Optional[str] = Field(None, description=\"行业代码\")\n    sector: str = Field(..., description=\"所属板块\")\n    list_date: date = Field(..., description=\"上市日期\")\n    delist_date: Optional[date] = Field(None, description=\"退市日期\")\n    area: str = Field(..., description=\"所在地区\")\n    market_cap: Optional[float] = Field(None, description=\"总市值\")\n    float_cap: Optional[float] = Field(None, description=\"流通市值\")\n    total_shares: Optional[float] = Field(None, description=\"总股本\")\n    float_shares: Optional[float] = Field(None, description=\"流通股本\")\n    currency: str = Field(default=\"CNY\", description=\"交易货币\")\n    status: StockStatus = Field(default=StockStatus.LISTED, description=\"上市状态\")\n    is_hs: bool = Field(default=False, description=\"是否沪深港通标的\")\n\n    @validator('symbol')\n    def validate_symbol(cls, v):\n        if not v.isdigit() or len(v) != 6:\n            raise ValueError('股票代码必须是6位数字')\n        return v\n\n\nclass StockDailyQuote(BaseStockModel):\n    \"\"\"股票日线行情模型\"\"\"\n    symbol: str = Field(..., description=\"股票代码\")\n    trade_date: date = Field(..., description=\"交易日期\")\n    open: float = Field(..., description=\"开盘价\")\n    high: float = Field(..., description=\"最高价\")\n    low: float = Field(..., description=\"最低价\")\n    close: float = Field(..., description=\"收盘价\")\n    pre_close: float = Field(..., description=\"前收盘价\")\n    change: float = Field(..., description=\"涨跌额\")\n    pct_chg: float = Field(..., description=\"涨跌幅(%)\")\n    volume: float = Field(..., description=\"成交量(股)\")\n    amount: float = Field(..., description=\"成交额(元)\")\n    turnover_rate: Optional[float] = Field(None, description=\"换手率(%)\")\n    volume_ratio: Optional[float] = Field(None, description=\"量比\")","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/models/stock_data_models.py#L77-L113","documentation":"A Pydantic validator on the StockBaseModel.symbol field requires the symbol to be exactly 6 numeric digits (Chinese A-share style, e.g. '600519'). Any value failing v.isdigit() or len(v) != 6 causes pydantic.ValidationError wrapping this ValueError at model instantiation. This enforces the A-share symbol convention before data enters the pipeline.","triggerScenarios":"Instantiating any StockBaseModel subclass (e.g. StockDailyQuote) with symbol='AAPL', '00700.HK', '600519.SH', '0001', or '60051a' — anything not a bare 6-digit string.","commonSituations":"Feeding US/HK tickers or suffixed A-share codes (with .SH/.SZ/.BJ) from external data sources into these models; frontends passing integers or zero-stripped codes; migrating from a library that accepted exchange-suffixed symbols.","solutions":["Strip exchange suffixes before constructing the model: use '600519' not '600519.SH' or '600519.SZ'.","Normalize upstream data: symbol.split('.')[0] or regex-extract the 6-digit core, and zero-pad shorter codes with zfill(6).","If you need non-A-share symbols, validate the market first and only route A-share data through these models, or extend the validator for other markets."],"exampleFix":"# before\nquote = StockDailyQuote(symbol=\"600519.SH\", ...)\n\n# after\nquote = StockDailyQuote(symbol=\"600519.SH\".split(\".\")[0], ...)  # or normalize: symbol.zfill(6)","handlingStrategy":"type-guard","validationCode":"import re\ndef normalize_a_share_symbol(sym) -> str:\n    s = str(sym).strip()\n    m = re.search(r\"\\d{6}\", s)  # extract 6-digit core from '600519.SH' etc.\n    if not m:\n        raise ValueError(f\"{sym!r} is not a valid A-share symbol\")\n    return m.group(0)\n\nquote = StockDailyQuote(symbol=normalize_a_share_symbol(raw_symbol), ...)","typeGuard":"def is_a_share_symbol(v) -> bool:\n    \"\"\"Type guard: True if v is a bare 6-digit A-share code.\"\"\"\n    return isinstance(v, str) and v.isdigit() and len(v) == 6","tryCatchPattern":"from pydantic import ValidationError\ntry:\n    quote = StockDailyQuote(symbol=sym, ...)\nexcept ValidationError as e:\n    if \"股票代码必须是6位数字\" in str(e):\n        sym = normalize_a_share_symbol(sym)\n        quote = StockDailyQuote(symbol=sym, ...)\n    else:\n        raise","preventionTips":["Always split off exchange suffixes: symbol.split('.')[0].","Zero-pad numeric codes from APIs that strip leading zeros: str(code).zfill(6).","Route only A-share data through these models; validate market before construction."],"tags":["pydantic","validation","symbol","a-share","stock-data"],"backgroundTag":"schema-validation-failed","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}