{
  "id": "python/pytest-sqlalchemy-fixture-rollback",
  "signature": "sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint \"users_email_key\"",
  "signature_zh": "sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) 重复键值违反唯一约束 \"users_email_key\"",
  "regex": "sqlalchemy\\.exc\\.IntegrityError:\\ \\(psycopg2\\.errors\\.UniqueViolation\\)\\ duplicate\\ key\\ value\\ violates\\ unique\\ constraint\\ \"users_email_key\"",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "The database fixture does not roll back transactions between tests, causing data from previous tests to persist.",
  "root_cause_type": "generic",
  "root_cause_zh": "数据库 fixture 未在测试之间回滚事务，导致先前测试的数据持久化。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This is a workaround that does not fix the underlying state leakage and may lead to other issues.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This is slow and may not be feasible for large test suites.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.fixture(scope='function')\ndef db_session():\n    connection = engine.connect()\n    transaction = connection.begin()\n    session = Session(bind=connection)\n    yield session\n    session.close()\n    transaction.rollback()\n    connection.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use pytest-sqlalchemy's fixtures or factory_boy with a session that rolls back after each test.",
      "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": "2025-11-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}