{
  "id": "python/unittest-mock-autospec-missing",
  "signature": "AttributeError: Mock object has no attribute 'fetch_user'",
  "signature_zh": "AttributeError: Mock 对象没有属性 'fetch_user'",
  "regex": "AttributeError:\\ Mock\\ object\\ has\\ no\\ attribute\\ 'fetch_user'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A plain MagicMock was used instead of create_autospec, so typos in method names are silently accepted until the mock is used as the real object and the attribute is looked up.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用了普通 MagicMock 而非 create_autospec，方法名拼写错误被静默接受，直到 mock 被当作真实对象使用并查找属性时才暴露。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Fixes one symptom but the mock still accepts any typo, so the next misspelling fails the same way.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses the ability to assert calls and may trigger real I/O or DB access.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from unittest.mock import create_autospec\nmock_svc = create_autospec(UserService, instance=True)\n# mock_svc.fetch_user now exists and typo'd names raise AttributeError",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from unittest.mock import Mock\nmock_svc = Mock(spec=UserService)",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}