{
  "id": "python/sqlalchemy-attribute-error-lazy-load",
  "signature": "AttributeError: 'User' object has no attribute 'addresses'",
  "signature_zh": "AttributeError：'User' 对象没有属性 'addresses'",
  "regex": "AttributeError:\\ 'User'\\ object\\ has\\ no\\ attribute\\ 'addresses'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Relationship not defined or not loaded due to lazy loading outside session.",
  "root_cause_type": "generic",
  "root_cause_zh": "关系未定义或由于在会话外延迟加载而未加载。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding the attribute manually to the class.",
      "why_fails": "Relationship must be defined via SQLAlchemy ORM; manual attribute breaks mapping.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using getattr with default but still accessing lazy attribute.",
      "why_fails": "Underlying relationship still not loaded; returns None incorrectly.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Define relationship in model class.",
      "success_rate": 0.95,
      "how": "class User(Base):\n    __tablename__ = 'users'\n    id = Column(Integer, primary_key=True)\n    addresses = relationship('Address', back_populates='user')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Eagerly load relationship in query.",
      "success_rate": 0.9,
      "how": "user = session.query(User).options(joinedload(User.addresses)).first()\nprint(user.addresses)  # Now available",
      "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-09-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}