{
  "id": "python/django-multiple-objects-returned",
  "signature": "django.core.exceptions.MultipleObjectsReturned: get() returned more than one MyModel -- it returned 2!",
  "signature_zh": "多对象返回错误：get() 返回了多个 MyModel 实例",
  "regex": "django\\.core\\.exceptions\\.MultipleObjectsReturned:\\ get\\(\\)\\ returned\\ more\\ than\\ one\\ MyModel\\ \\-\\-\\ it\\ returned\\ 2!",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "使用 get() 查询时，条件匹配了多个记录",
  "root_cause_type": "generic",
  "root_cause_zh": "get() 方法期望唯一结果，但查询条件返回了多条记录",
  "versions": [
    {
      "version": "3.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "忽略错误继续执行",
      "why_fails": "异常会导致程序中断，无法忽略",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "使用 filter() 代替 get()",
      "why_fails": "filter() 返回 QuerySet，后续代码可能期望单个对象",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "使用 filter() 并获取第一个对象",
      "success_rate": 0.95,
      "how": "obj = MyModel.objects.filter(condition).first()",
      "condition": "",
      "sources": []
    },
    {
      "action": "添加唯一约束",
      "success_rate": 0.9,
      "how": "在模型字段中添加 unique=True 或使用 unique_together",
      "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-10-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}