prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Error 500 when visiting /admin/users/1 - AttributeError: 'NoneType' object has no attribute 'get_score'
  **Environment**:
  
  - CTFd Version/Commit: HEAD
  - Operating System: Docker image based off official Dockerfile
  - Web Browser and Version: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15
  
  **What happened?**
  500 Internal server error
  
  **What did you expect to happen?**
  Show the admin user details when in team mode
  
  **How to reproduce your issue**
  * visited the `/admin/users/1`
  * this seems due to the fact that, when in team mode, the admin user does not belong to any team and, for some reason, this one returns `None`
  
  ```python
      @hybrid_property
      def account(self):
          from CTFd.utils import get_config
  
          user_mode = get_config("user_mode")
          if user_mode == "teams":
              return self.team
          elif user_mode == "users":
              return self
  ```
  
  **Any associated stack traces or error logs**
  ```
  ERROR [CTFd] Exception on /admin/users/1 [GET]
  --
  Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
  response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask_restx/api.py", line 639, in error_router
  return original_handler(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
  raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
  rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/CTFd/CTFd/utils/decorators/__init__.py", line 133, in admins_only_wrapper
  return f(*args, **kwargs)
  File "/opt/CTFd/CTFd/admin/users.py", line 91, in users_detail
  score = user.account.get_score(admin=True)
  AttributeError: 'NoneType' object has no attribute 'get_score'
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `CTFd/admin/users.py`
  Content:
  ```
  1 from flask import render_template, request, url_for
  2 from sqlalchemy.sql import not_
  3 
  4 from CTFd.admin import admin
  5 from CTFd.models import Challenges, Tracking, Users
  6 from CTFd.utils import get_config
  7 from CTFd.utils.decorators import admins_only
  8 from CTFd.utils.modes import TEAMS_MODE
  9 
  10 
  11 @admin.route("/admin/users")
  12 @admins_only
  13 def users_listing():
  14     q = request.args.get("q")
  15     field = request.args.get("field")
  16     page = abs(request.args.get("page", 1, type=int))
  17     filters = []
  18     users = []
  19 
  20     if q:
  21         # The field exists as an exposed column
  22         if Users.__mapper__.has_property(field):
  23             filters.append(getattr(Users, field).like("%{}%".format(q)))
  24 
  25     if q and field == "ip":
  26         users = (
  27             Users.query.join(Tracking, Users.id == Tracking.user_id)
  28             .filter(Tracking.ip.like("%{}%".format(q)))
  29             .order_by(Users.id.asc())
  30             .paginate(page=page, per_page=50)
  31         )
  32     else:
  33         users = (
  34             Users.query.filter(*filters)
  35             .order_by(Users.id.asc())
  36             .paginate(page=page, per_page=50)
  37         )
  38 
  39     args = dict(request.args)
  40     args.pop("page", 1)
  41 
  42     return render_template(
  43         "admin/users/users.html",
  44         users=users,
  45         prev_page=url_for(request.endpoint, page=users.prev_num, **args),
  46         next_page=url_for(request.endpoint, page=users.next_num, **args),
  47         q=q,
  48         field=field,
  49     )
  50 
  51 
  52 @admin.route("/admin/users/new")
  53 @admins_only
  54 def users_new():
  55     return render_template("admin/users/new.html")
  56 
  57 
  58 @admin.route("/admin/users/<int:user_id>")
  59 @admins_only
  60 def users_detail(user_id):
  61     # Get user object
  62     user = Users.query.filter_by(id=user_id).first_or_404()
  63 
  64     # Get the user's solves
  65     solves = user.get_solves(admin=True)
  66 
  67     # Get challenges that the user is missing
  68     if get_config("user_mode") == TEAMS_MODE:
  69         if user.team:
  70             all_solves = user.team.get_solves(admin=True)
  71         else:
  72             all_solves = user.get_solves(admin=True)
  73     else:
  74         all_solves = user.get_solves(admin=True)
  75 
  76     solve_ids = [s.challenge_id for s in all_solves]
  77     missing = Challenges.query.filter(not_(Challenges.id.in_(solve_ids))).all()
  78 
  79     # Get IP addresses that the User has used
  80     addrs = (
  81         Tracking.query.filter_by(user_id=user_id).order_by(Tracking.date.desc()).all()
  82     )
  83 
  84     # Get Fails
  85     fails = user.get_fails(admin=True)
  86 
  87     # Get Awards
  88     awards = user.get_awards(admin=True)
  89 
  90     # Get user properties
  91     score = user.account.get_score(admin=True)
  92     place = user.account.get_place(admin=True)
  93 
  94     return render_template(
  95         "admin/users/user.html",
  96         solves=solves,
  97         user=user,
  98         addrs=addrs,
  99         score=score,
  100         missing=missing,
  101         place=place,
  102         fails=fails,
  103         awards=awards,
  104     )
  105
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/CTFd/admin/users.py b/CTFd/admin/users.py
  --- a/CTFd/admin/users.py
  +++ b/CTFd/admin/users.py
  @@ -87,9 +87,14 @@
       # Get Awards
       awards = user.get_awards(admin=True)
   
  -    # Get user properties
  -    score = user.account.get_score(admin=True)
  -    place = user.account.get_place(admin=True)
  +    # Check if the user has an account (team or user)
  +    # so that we don't throw an error if they dont
  +    if user.account:
  +        score = user.account.get_score(admin=True)
  +        place = user.account.get_place(admin=True)
  +    else:
  +        score = None
  +        place = None
   
       return render_template(
           "admin/users/user.html",
  
verification_info: {"golden_diff": "diff --git a/CTFd/admin/users.py b/CTFd/admin/users.py\n--- a/CTFd/admin/users.py\n+++ b/CTFd/admin/users.py\n@@ -87,9 +87,14 @@\n     # Get Awards\n     awards = user.get_awards(admin=True)\n \n-    # Get user properties\n-    score = user.account.get_score(admin=True)\n-    place = user.account.get_place(admin=True)\n+    # Check if the user has an account (team or user)\n+    # so that we don't throw an error if they dont\n+    if user.account:\n+        score = user.account.get_score(admin=True)\n+        place = user.account.get_place(admin=True)\n+    else:\n+        score = None\n+        place = None\n \n     return render_template(\n         \"admin/users/user.html\",\n", "issue": "Error 500 when visiting /admin/users/1 - AttributeError: 'NoneType' object has no attribute 'get_score'\n**Environment**:\r\n\r\n- CTFd Version/Commit: HEAD\r\n- Operating System: Docker image based off official Dockerfile\r\n- Web Browser and Version: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15\r\n\r\n**What happened?**\r\n500 Internal server error\r\n\r\n**What did you expect to happen?**\r\nShow the admin user details when in team mode\r\n\r\n**How to reproduce your issue**\r\n* visited the `/admin/users/1`\r\n* this seems due to the fact that, when in team mode, the admin user does not belong to any team and, for some reason, this one returns `None`\r\n\r\n```python\r\n    @hybrid_property\r\n    def account(self):\r\n        from CTFd.utils import get_config\r\n\r\n        user_mode = get_config(\"user_mode\")\r\n        if user_mode == \"teams\":\r\n            return self.team\r\n        elif user_mode == \"users\":\r\n            return self\r\n```\r\n\r\n**Any associated stack traces or error logs**\r\n```\r\nERROR [CTFd] Exception on /admin/users/1 [GET]\r\n--\r\nTraceback (most recent call last):\r\nFile \"/usr/local/lib/python3.7/site-packages/flask/app.py\", line 2447, in wsgi_app\r\nresponse = self.full_dispatch_request()\r\nFile \"/usr/local/lib/python3.7/site-packages/flask/app.py\", line 1952, in full_dispatch_request\r\nrv = self.handle_user_exception(e)\r\nFile \"/usr/local/lib/python3.7/site-packages/flask_restx/api.py\", line 639, in error_router\r\nreturn original_handler(e)\r\nFile \"/usr/local/lib/python3.7/site-packages/flask/app.py\", line 1821, in handle_user_exception\r\nreraise(exc_type, exc_value, tb)\r\nFile \"/usr/local/lib/python3.7/site-packages/flask/_compat.py\", line 39, in reraise\r\nraise value\r\nFile \"/usr/local/lib/python3.7/site-packages/flask/app.py\", line 1950, in full_dispatch_request\r\nrv = self.dispatch_request()\r\nFile \"/usr/local/lib/python3.7/site-packages/flask/app.py\", line 1936, in dispatch_request\r\nreturn self.view_functions[rule.endpoint](**req.view_args)\r\nFile \"/opt/CTFd/CTFd/utils/decorators/__init__.py\", line 133, in admins_only_wrapper\r\nreturn f(*args, **kwargs)\r\nFile \"/opt/CTFd/CTFd/admin/users.py\", line 91, in users_detail\r\nscore = user.account.get_score(admin=True)\r\nAttributeError: 'NoneType' object has no attribute 'get_score'\r\n```\r\n\n", "before_files": [{"content": "from flask import render_template, request, url_for\nfrom sqlalchemy.sql import not_\n\nfrom CTFd.admin import admin\nfrom CTFd.models import Challenges, Tracking, Users\nfrom CTFd.utils import get_config\nfrom CTFd.utils.decorators import admins_only\nfrom CTFd.utils.modes import TEAMS_MODE\n\n\n@admin.route(\"/admin/users\")\n@admins_only\ndef users_listing():\n    q = request.args.get(\"q\")\n    field = request.args.get(\"field\")\n    page = abs(request.args.get(\"page\", 1, type=int))\n    filters = []\n    users = []\n\n    if q:\n        # The field exists as an exposed column\n        if Users.__mapper__.has_property(field):\n            filters.append(getattr(Users, field).like(\"%{}%\".format(q)))\n\n    if q and field == \"ip\":\n        users = (\n            Users.query.join(Tracking, Users.id == Tracking.user_id)\n            .filter(Tracking.ip.like(\"%{}%\".format(q)))\n            .order_by(Users.id.asc())\n            .paginate(page=page, per_page=50)\n        )\n    else:\n        users = (\n            Users.query.filter(*filters)\n            .order_by(Users.id.asc())\n            .paginate(page=page, per_page=50)\n        )\n\n    args = dict(request.args)\n    args.pop(\"page\", 1)\n\n    return render_template(\n        \"admin/users/users.html\",\n        users=users,\n        prev_page=url_for(request.endpoint, page=users.prev_num, **args),\n        next_page=url_for(request.endpoint, page=users.next_num, **args),\n        q=q,\n        field=field,\n    )\n\n\n@admin.route(\"/admin/users/new\")\n@admins_only\ndef users_new():\n    return render_template(\"admin/users/new.html\")\n\n\n@admin.route(\"/admin/users/<int:user_id>\")\n@admins_only\ndef users_detail(user_id):\n    # Get user object\n    user = Users.query.filter_by(id=user_id).first_or_404()\n\n    # Get the user's solves\n    solves = user.get_solves(admin=True)\n\n    # Get challenges that the user is missing\n    if get_config(\"user_mode\") == TEAMS_MODE:\n        if user.team:\n            all_solves = user.team.get_solves(admin=True)\n        else:\n            all_solves = user.get_solves(admin=True)\n    else:\n        all_solves = user.get_solves(admin=True)\n\n    solve_ids = [s.challenge_id for s in all_solves]\n    missing = Challenges.query.filter(not_(Challenges.id.in_(solve_ids))).all()\n\n    # Get IP addresses that the User has used\n    addrs = (\n        Tracking.query.filter_by(user_id=user_id).order_by(Tracking.date.desc()).all()\n    )\n\n    # Get Fails\n    fails = user.get_fails(admin=True)\n\n    # Get Awards\n    awards = user.get_awards(admin=True)\n\n    # Get user properties\n    score = user.account.get_score(admin=True)\n    place = user.account.get_place(admin=True)\n\n    return render_template(\n        \"admin/users/user.html\",\n        solves=solves,\n        user=user,\n        addrs=addrs,\n        score=score,\n        missing=missing,\n        place=place,\n        fails=fails,\n        awards=awards,\n    )\n", "path": "CTFd/admin/users.py"}], "after_files": [{"content": "from flask import render_template, request, url_for\nfrom sqlalchemy.sql import not_\n\nfrom CTFd.admin import admin\nfrom CTFd.models import Challenges, Tracking, Users\nfrom CTFd.utils import get_config\nfrom CTFd.utils.decorators import admins_only\nfrom CTFd.utils.modes import TEAMS_MODE\n\n\n@admin.route(\"/admin/users\")\n@admins_only\ndef users_listing():\n    q = request.args.get(\"q\")\n    field = request.args.get(\"field\")\n    page = abs(request.args.get(\"page\", 1, type=int))\n    filters = []\n    users = []\n\n    if q:\n        # The field exists as an exposed column\n        if Users.__mapper__.has_property(field):\n            filters.append(getattr(Users, field).like(\"%{}%\".format(q)))\n\n    if q and field == \"ip\":\n        users = (\n            Users.query.join(Tracking, Users.id == Tracking.user_id)\n            .filter(Tracking.ip.like(\"%{}%\".format(q)))\n            .order_by(Users.id.asc())\n            .paginate(page=page, per_page=50)\n        )\n    else:\n        users = (\n            Users.query.filter(*filters)\n            .order_by(Users.id.asc())\n            .paginate(page=page, per_page=50)\n        )\n\n    args = dict(request.args)\n    args.pop(\"page\", 1)\n\n    return render_template(\n        \"admin/users/users.html\",\n        users=users,\n        prev_page=url_for(request.endpoint, page=users.prev_num, **args),\n        next_page=url_for(request.endpoint, page=users.next_num, **args),\n        q=q,\n        field=field,\n    )\n\n\n@admin.route(\"/admin/users/new\")\n@admins_only\ndef users_new():\n    return render_template(\"admin/users/new.html\")\n\n\n@admin.route(\"/admin/users/<int:user_id>\")\n@admins_only\ndef users_detail(user_id):\n    # Get user object\n    user = Users.query.filter_by(id=user_id).first_or_404()\n\n    # Get the user's solves\n    solves = user.get_solves(admin=True)\n\n    # Get challenges that the user is missing\n    if get_config(\"user_mode\") == TEAMS_MODE:\n        if user.team:\n            all_solves = user.team.get_solves(admin=True)\n        else:\n            all_solves = user.get_solves(admin=True)\n    else:\n        all_solves = user.get_solves(admin=True)\n\n    solve_ids = [s.challenge_id for s in all_solves]\n    missing = Challenges.query.filter(not_(Challenges.id.in_(solve_ids))).all()\n\n    # Get IP addresses that the User has used\n    addrs = (\n        Tracking.query.filter_by(user_id=user_id).order_by(Tracking.date.desc()).all()\n    )\n\n    # Get Fails\n    fails = user.get_fails(admin=True)\n\n    # Get Awards\n    awards = user.get_awards(admin=True)\n\n    # Check if the user has an account (team or user)\n    # so that we don't throw an error if they dont\n    if user.account:\n        score = user.account.get_score(admin=True)\n        place = user.account.get_place(admin=True)\n    else:\n        score = None\n        place = None\n\n    return render_template(\n        \"admin/users/user.html\",\n        solves=solves,\n        user=user,\n        addrs=addrs,\n        score=score,\n        missing=missing,\n        place=place,\n        fails=fails,\n        awards=awards,\n    )\n", "path": "CTFd/admin/users.py"}]}