{
  "id": "python/pydantic-type-error-int-parsing-string",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for Model\nage\n  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='abc', input_type=str]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 1 个验证错误 (Model)\nage\n  输入应为有效整数，无法将字符串解析为整数 [type=int_parsing, input_value='abc', input_type=str]",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ Model\\\nage\\\n\\ \\ Input\\ should\\ be\\ a\\ valid\\ integer,\\ unable\\ to\\ parse\\ string\\ as\\ an\\ integer\\ \\[type=int_parsing,\\ input_value='abc',\\ input_type=str\\]",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Pydantic v2's stricter parsing rejects non-numeric strings for `int` fields where v1 would silently coerce or raise a different message.",
  "root_cause_type": "generic",
  "root_cause_zh": "Pydantic v2 更严格的解析会拒绝非数字字符串赋给 `int` 字段，而 v1 会静默转换或抛出不同消息。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Wrapping in `try/except ValueError` does not catch `ValidationError` in v2 because it is a separate exception type.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using `int(value)` before passing to the model defeats the purpose and still raises for non-numeric input.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use a custom validator: `@field_validator('age', mode='before')\n@classmethod\ndef parse_age(cls, v):\n    return int(v) if str(v).isdigit() else 0`",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "Change the field type to `Union[int, str]` and validate downstream, or use `Annotated[int, BeforeValidator(lambda v: int(v) if str(v).isdigit() else 0)]`.",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}