{
  "id": "python/sqlalchemy-query-too-many-rows",
  "signature": "sqlalchemy.exc.MultipleResultsFound: Multiple rows were found for one()",
  "signature_zh": "sqlalchemy.exc.MultipleResultsFound: 对于 one() 找到了多行",
  "regex": "sqlalchemy\\.exc\\.MultipleResultsFound:\\ Multiple\\ rows\\ were\\ found\\ for\\ one\\(\\)",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Using the one() method on a query that returns more than one row, which expects exactly one.",
  "root_cause_type": "generic",
  "root_cause_zh": "对返回多行的查询使用 one() 方法，而该方法期望只返回一行。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using first() instead without checking",
      "why_fails": "first() returns None if no rows, masking potential logic errors.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the error and assuming one row",
      "why_fails": "The error will still occur.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use one_or_none() to handle zero or one result",
      "success_rate": 0.95,
      "how": "user = session.query(User).filter_by(id=user_id).one_or_none()\nif user is None:\n    # Handle not found\n    pass",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use scalar() for single column queries",
      "success_rate": 0.9,
      "how": "count = session.query(func.count(User.id)).scalar()",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}