{
  "id": "python/unittest-testcase-assertcountequal-unhashable",
  "signature": "TypeError: unhashable type: 'dict'",
  "signature_zh": "TypeError: 不可哈希的类型: 'dict'",
  "regex": "TypeError:\\ unhashable\\ type:\\ 'dict'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "assertCountEqual builds a Counter of both sequences, which requires hashable elements. Lists of dicts fail because dict is unhashable.",
  "root_cause_type": "generic",
  "root_cause_zh": "assertCountEqual 会构建两个序列的 Counter，要求元素可哈希。字典列表因 dict 不可哈希而失败。",
  "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": "Loses key ordering independence; two equal dicts with different insertion order produce different strings and the test fails spuriously.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "assertEqual is order-sensitive and fails when the sequences contain the same items in a different order.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "actual = sorted(actual, key=lambda d: d['id'])\nexpected = sorted(expected, key=lambda d: d['id'])\nself.assertEqual(actual, expected)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "from collections import Counter\nself.assertEqual(\n    Counter(frozenset(d.items()) for d in actual),\n    Counter(frozenset(d.items()) for d in expected),\n)",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}