{
  "id": "python/sqlalchemy-missing-session-commit",
  "signature": "sqlalchemy.exc.PendingRollbackError: Can't reconnect until invalid transaction is rolled back.  Please rollback() fully before proceeding",
  "signature_zh": "sqlalchemy.exc.PendingRollbackError: 在无效事务回滚之前无法重新连接。请先完整执行 rollback() 后再继续。",
  "regex": "sqlalchemy\\.exc\\.PendingRollbackError:\\ Can't\\ reconnect\\ until\\ invalid\\ transaction\\ is\\ rolled\\ back\\.\\ \\ Please\\ rollback\\(\\)\\ fully\\ before\\ proceeding",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A previous SQL operation failed (e.g., constraint violation) but the session was not rolled back. Subsequent operations on the same session trigger this error because the transaction remains in a failed state.",
  "root_cause_type": "generic",
  "root_cause_zh": "之前的 SQL 操作失败（如违反约束），但会话未回滚。后续在同一会话上的操作会触发此错误，因为事务仍处于失败状态。",
  "versions": [
    {
      "version": "1.4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.0.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "close() does not reset the transaction state; it only releases connections. The next session usage still carries the failed transaction.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is persistent until rollback is explicitly called; retrying the same failed operation doesn't clear the invalid transaction flag.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Explicitly rollback the session after any exception: try: session.commit() except: session.rollback() raise",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use a context manager pattern: with session.begin(): # operations - automatically rolls back on exception",
      "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-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}