{
  "id": "python/pydantic-validation-error-int-parsing",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for Product\nprice\n  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='19.99', input_type=str]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 产品模型验证错误：price 字段无法将字符串解析为整数",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ Product\\\nprice\\\n\\ \\ Input\\ should\\ be\\ a\\ valid\\ integer,\\ unable\\ to\\ parse\\ string\\ as\\ an\\ integer\\ \\[type=int_parsing,\\ input_value='19\\.99',\\ input_type=str\\]",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A string value containing a decimal or non-numeric characters was passed to an int-typed field. Pydantic v2 strict parsing rejects strings like '19.99' for int fields.",
  "root_cause_type": "generic",
  "root_cause_zh": "向 int 类型字段传入了包含小数或非数字字符的字符串。Pydantic v2 严格解析会拒绝 '19.99' 这类字符串赋值给 int 字段。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "int('19.99') raises ValueError because Python cannot directly cast a decimal string to int.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses numeric semantics; downstream arithmetic operations will fail with TypeError.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from decimal import Decimal\nfrom pydantic import BaseModel\n\nclass Product(BaseModel):\n    price: Decimal",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from pydantic import BaseModel, field_validator\n\nclass Product(BaseModel):\n    price: int\n\n    @field_validator('price', mode='before')\n    @classmethod\n    def parse_price(cls, v):\n        return int(float(v))",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}