prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Plugins not loaded with Gunicorn
  
  ### Environment
  
  * Nautobot version (Docker tag too if applicable): 2.2.1
  * Python version: 3.11
  * Database platform, version: psql
  * Middleware(s):
  
  
  ### Steps to Reproduce
  1. Use systemd
  2. With gunicorn 21.2.0 or 22.0.0
  
  
  <!-- What did you expect to happen? -->
  ### Expected Behavior
  
  All applications to show 
  
  ### Observed Behavior
  
  We attempted to upgrade our dev environment from 2.1.9 to 2.2.1 but are hitting a weird issue where our plugins are reported as missing.  We are only loading 1 or 2 basic plugins right now while we work on updating all our other plugins for 2.x.  Oddly we are only seeing this issue on 1 out of 3 identical servers with identical Nautobot installs.
  
  This looks very much like this issue from 2021: [Plugin Load Failure · Issue #95 · nautobot/nautobot (github.com)](https://github.com/nautobot/nautobot/issues/95)
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `nautobot/core/wsgi.py`
  Content:
  ```
  1 import logging
  2 import os
  3 
  4 from django.core import cache
  5 from django.core.wsgi import get_wsgi_application
  6 from django.db import connections
  7 
  8 os.environ["DJANGO_SETTINGS_MODULE"] = "nautobot_config"
  9 
  10 # Use try/except because we might not be running uWSGI. If `settings.WEBSERVER_WARMUP` is `True`,
  11 # will first call `get_internal_wsgi_application` which does not have `uwsgi` module loaded
  12 # already. Therefore, `settings.WEBSERVER_WARMUP` to `False` for this code to be loaded.
  13 try:
  14     import uwsgidecorators
  15 
  16     @uwsgidecorators.postfork
  17     def fix_uwsgi():
  18         import uwsgi
  19 
  20         logging.getLogger(__name__).info(
  21             f"Closing existing DB and cache connections on worker {uwsgi.worker_id()} after uWSGI forked ..."
  22         )
  23         connections.close_all()
  24         cache.close_caches()
  25 
  26 except ImportError:
  27     pass
  28 
  29 application = get_wsgi_application()
  30
  ```
  --- 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/nautobot/core/wsgi.py b/nautobot/core/wsgi.py
  --- a/nautobot/core/wsgi.py
  +++ b/nautobot/core/wsgi.py
  @@ -1,11 +1,18 @@
   import logging
  -import os
   
   from django.core import cache
   from django.core.wsgi import get_wsgi_application
   from django.db import connections
   
  -os.environ["DJANGO_SETTINGS_MODULE"] = "nautobot_config"
  +import nautobot
  +
  +# This is the Django default left here for visibility on how the Nautobot pattern
  +# differs.
  +# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "nautobot.core.settings")
  +
  +# Instead of just pointing to `DJANGO_SETTINGS_MODULE` and letting Django run with it,
  +# we're using the custom Nautobot loader code to read environment or config path for us.
  +nautobot.setup()
   
   # Use try/except because we might not be running uWSGI. If `settings.WEBSERVER_WARMUP` is `True`,
   # will first call `get_internal_wsgi_application` which does not have `uwsgi` module loaded
  
verification_info: {"golden_diff": "diff --git a/nautobot/core/wsgi.py b/nautobot/core/wsgi.py\n--- a/nautobot/core/wsgi.py\n+++ b/nautobot/core/wsgi.py\n@@ -1,11 +1,18 @@\n import logging\n-import os\n \n from django.core import cache\n from django.core.wsgi import get_wsgi_application\n from django.db import connections\n \n-os.environ[\"DJANGO_SETTINGS_MODULE\"] = \"nautobot_config\"\n+import nautobot\n+\n+# This is the Django default left here for visibility on how the Nautobot pattern\n+# differs.\n+# os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"nautobot.core.settings\")\n+\n+# Instead of just pointing to `DJANGO_SETTINGS_MODULE` and letting Django run with it,\n+# we're using the custom Nautobot loader code to read environment or config path for us.\n+nautobot.setup()\n \n # Use try/except because we might not be running uWSGI. If `settings.WEBSERVER_WARMUP` is `True`,\n # will first call `get_internal_wsgi_application` which does not have `uwsgi` module loaded\n", "issue": "Plugins not loaded with Gunicorn\n\r\n### Environment\r\n\r\n* Nautobot version (Docker tag too if applicable): 2.2.1\r\n* Python version: 3.11\r\n* Database platform, version: psql\r\n* Middleware(s):\r\n\r\n\r\n### Steps to Reproduce\r\n1. Use systemd\r\n2. With gunicorn 21.2.0 or 22.0.0\r\n\r\n\r\n<!-- What did you expect to happen? -->\r\n### Expected Behavior\r\n\r\nAll applications to show \r\n\r\n### Observed Behavior\r\n\r\nWe attempted to upgrade our dev environment from 2.1.9 to 2.2.1 but are hitting a weird issue where our plugins are reported as missing.  We are only loading 1 or 2 basic plugins right now while we work on updating all our other plugins for 2.x.  Oddly we are only seeing this issue on 1 out of 3 identical servers with identical Nautobot installs.\r\n\r\nThis looks very much like this issue from 2021: [Plugin Load Failure \u00b7 Issue #95 \u00b7 nautobot/nautobot (github.com)](https://github.com/nautobot/nautobot/issues/95)\n", "before_files": [{"content": "import logging\nimport os\n\nfrom django.core import cache\nfrom django.core.wsgi import get_wsgi_application\nfrom django.db import connections\n\nos.environ[\"DJANGO_SETTINGS_MODULE\"] = \"nautobot_config\"\n\n# Use try/except because we might not be running uWSGI. If `settings.WEBSERVER_WARMUP` is `True`,\n# will first call `get_internal_wsgi_application` which does not have `uwsgi` module loaded\n# already. Therefore, `settings.WEBSERVER_WARMUP` to `False` for this code to be loaded.\ntry:\n    import uwsgidecorators\n\n    @uwsgidecorators.postfork\n    def fix_uwsgi():\n        import uwsgi\n\n        logging.getLogger(__name__).info(\n            f\"Closing existing DB and cache connections on worker {uwsgi.worker_id()} after uWSGI forked ...\"\n        )\n        connections.close_all()\n        cache.close_caches()\n\nexcept ImportError:\n    pass\n\napplication = get_wsgi_application()\n", "path": "nautobot/core/wsgi.py"}], "after_files": [{"content": "import logging\n\nfrom django.core import cache\nfrom django.core.wsgi import get_wsgi_application\nfrom django.db import connections\n\nimport nautobot\n\n# This is the Django default left here for visibility on how the Nautobot pattern\n# differs.\n# os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"nautobot.core.settings\")\n\n# Instead of just pointing to `DJANGO_SETTINGS_MODULE` and letting Django run with it,\n# we're using the custom Nautobot loader code to read environment or config path for us.\nnautobot.setup()\n\n# Use try/except because we might not be running uWSGI. If `settings.WEBSERVER_WARMUP` is `True`,\n# will first call `get_internal_wsgi_application` which does not have `uwsgi` module loaded\n# already. Therefore, `settings.WEBSERVER_WARMUP` to `False` for this code to be loaded.\ntry:\n    import uwsgidecorators\n\n    @uwsgidecorators.postfork\n    def fix_uwsgi():\n        import uwsgi\n\n        logging.getLogger(__name__).info(\n            f\"Closing existing DB and cache connections on worker {uwsgi.worker_id()} after uWSGI forked ...\"\n        )\n        connections.close_all()\n        cache.close_caches()\n\nexcept ImportError:\n    pass\n\napplication = get_wsgi_application()\n", "path": "nautobot/core/wsgi.py"}]}