{
  "id": "python/pytest-parallel-db-fixture-conflict",
  "signature": "sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked",
  "signature_zh": "sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) 数据库已锁定",
  "regex": "sqlalchemy\\.exc\\.OperationalError:\\ \\(sqlite3\\.OperationalError\\)\\ database\\ is\\ locked",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Multiple pytest-xdist workers share the same SQLite file; concurrent writes cause lock contention and OperationalError.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个 pytest-xdist worker 共享同一个 SQLite 文件；并发写入导致锁竞争和 OperationalError。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Reduces frequency but not correctness; long-running transactions still deadlock and CI slows down.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Defeats the purpose of parallel tests; CI time returns to serial levels.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "WAL helps readers but writers still serialize; contention remains under heavy xdist load.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.fixture(scope='session')\ndef db_url(tmp_path_factory, worker_id):\n    if worker_id == 'master':\n        path = tmp_path_factory.mktemp('db') / 'test.db'\n    else:\n        path = tmp_path_factory.mktemp(f'db_{worker_id}') / 'test.db'\n    return f'sqlite:///{path}'",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "# docker-compose.yml provides postgres\n# conftest.py\n@pytest.fixture(scope='session')\ndef db_url(worker_id):\n    return f'postgresql://test:test@localhost/test_{worker_id}'",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-11-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}