{
  "id": "python/jinja2-undefined-error",
  "signature": "jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'username'",
  "signature_zh": "jinja2.exceptions.UndefinedError: 'dict 对象' 没有属性 'username'。",
  "regex": "jinja2\\.exceptions\\.UndefinedError:\\ 'dict\\ object'\\ has\\ no\\ attribute\\ 'username'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Template references a variable or attribute that was not passed to render_template or does not exist on the provided object.",
  "root_cause_type": "generic",
  "root_cause_zh": "模板引用了未传递给 render_template 的变量，或提供的对象上不存在的属性。",
  "versions": [
    {
      "version": "3.1.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Undefined has no __bool__ short-circuit before attribute access; still raises.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Default already is Undefined; needs ChainableUndefined or StrictUndefined change, not reassignment.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use `{{ user.username if user else '' }}` or pass a default: `render_template('x.html', user=user or {})`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Enable ChainableUndefined: `app.jinja_env.undefined = jinja2.ChainableUndefined` to allow nested access without raising.",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}