We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support Django BASE_DIR being a pathlib.Path
As per [my blog post today](https://adamj.eu/tech/2020/03/16/use-pathlib-in-your-django-project/), this is changing in Django 3.1 but users may already be changing it now.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/scout_apm/django/apps.py`
Content:
```
1 # coding=utf-8
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 
4 from django.apps import AppConfig
5 from django.conf import settings
6 from django.test.signals import setting_changed
7 
8 import scout_apm.core
9 from scout_apm.core.config import scout_config
10 from scout_apm.django.instruments.huey import ensure_huey_instrumented
11 from scout_apm.django.instruments.sql import ensure_sql_instrumented
12 from scout_apm.django.instruments.template import ensure_templates_instrumented
13 
14 
15 class ScoutApmDjangoConfig(AppConfig):
16     name = "scout_apm"
17     verbose_name = "Scout Apm (Django)"
18 
19     def ready(self):
20         self.update_scout_config_from_django_settings()
21         setting_changed.connect(self.on_setting_changed)
22 
23         # Finish installing the agent. If the agent isn't installed for any
24         # reason, return without installing instruments
25         installed = scout_apm.core.install()
26         if not installed:
27             return
28 
29         self.install_middleware()
30 
31         # Setup Instruments
32         ensure_huey_instrumented()
33         ensure_sql_instrumented()
34         ensure_templates_instrumented()
35 
36     def update_scout_config_from_django_settings(self, **kwargs):
37         for name in dir(settings):
38             self.on_setting_changed(name)
39 
40     def on_setting_changed(self, setting, **kwargs):
41         if setting == "BASE_DIR":
42             scout_name = "application_root"
43         elif setting.startswith("SCOUT_"):
44             scout_name = setting.replace("SCOUT_", "").lower()
45         else:
46             return
47 
48         try:
49             value = getattr(settings, setting)
50         except AttributeError:
51             # It was removed
52             scout_config.unset(scout_name)
53         else:
54             scout_config.set(**{scout_name: value})
55 
56     def install_middleware(self):
57         """
58         Attempts to insert the ScoutApm middleware as the first middleware
59         (first on incoming requests, last on outgoing responses).
60         """
61         from django.conf import settings
62 
63         # If MIDDLEWARE is set, update that, with handling of tuple vs array forms
64         if getattr(settings, "MIDDLEWARE", None) is not None:
65             timing_middleware = "scout_apm.django.middleware.MiddlewareTimingMiddleware"
66             view_middleware = "scout_apm.django.middleware.ViewTimingMiddleware"
67 
68             if isinstance(settings.MIDDLEWARE, tuple):
69                 if timing_middleware not in settings.MIDDLEWARE:
70                     settings.MIDDLEWARE = (timing_middleware,) + settings.MIDDLEWARE
71                 if view_middleware not in settings.MIDDLEWARE:
72                     settings.MIDDLEWARE = settings.MIDDLEWARE + (view_middleware,)
73             else:
74                 if timing_middleware not in settings.MIDDLEWARE:
75                     settings.MIDDLEWARE.insert(0, timing_middleware)
76                 if view_middleware not in settings.MIDDLEWARE:
77                     settings.MIDDLEWARE.append(view_middleware)
78 
79         # Otherwise, we're doing old style middleware, do the same thing with
80         # the same handling of tuple vs array forms
81         else:
82             timing_middleware = (
83                 "scout_apm.django.middleware.OldStyleMiddlewareTimingMiddleware"
84             )
85             view_middleware = "scout_apm.django.middleware.OldStyleViewMiddleware"
86 
87             if isinstance(settings.MIDDLEWARE_CLASSES, tuple):
88                 if timing_middleware not in settings.MIDDLEWARE_CLASSES:
89                     settings.MIDDLEWARE_CLASSES = (
90                         timing_middleware,
91                     ) + settings.MIDDLEWARE_CLASSES
92 
93                 if view_middleware not in settings.MIDDLEWARE_CLASSES:
94                     settings.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES + (
95                         view_middleware,
96                     )
97             else:
98                 if timing_middleware not in settings.MIDDLEWARE_CLASSES:
99                     settings.MIDDLEWARE_CLASSES.insert(0, timing_middleware)
100                 if view_middleware not in settings.MIDDLEWARE_CLASSES:
101                     settings.MIDDLEWARE_CLASSES.append(view_middleware)
102
```
--- 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()

```

diff --git a/src/scout_apm/django/apps.py b/src/scout_apm/django/apps.py
--- a/src/scout_apm/django/apps.py
+++ b/src/scout_apm/django/apps.py
@@ -38,8 +38,10 @@
             self.on_setting_changed(name)
 
     def on_setting_changed(self, setting, **kwargs):
+        cast = None
         if setting == "BASE_DIR":
             scout_name = "application_root"
+            cast = str
         elif setting.startswith("SCOUT_"):
             scout_name = setting.replace("SCOUT_", "").lower()
         else:
@@ -51,6 +53,8 @@
             # It was removed
             scout_config.unset(scout_name)
         else:
+            if cast is not None:
+                value = cast(value)
             scout_config.set(**{scout_name: value})
 
     def install_middleware(self):

{"golden_diff": "diff --git a/src/scout_apm/django/apps.py b/src/scout_apm/django/apps.py\n--- a/src/scout_apm/django/apps.py\n+++ b/src/scout_apm/django/apps.py\n@@ -38,8 +38,10 @@\n             self.on_setting_changed(name)\n \n     def on_setting_changed(self, setting, **kwargs):\n+        cast = None\n         if setting == \"BASE_DIR\":\n             scout_name = \"application_root\"\n+            cast = str\n         elif setting.startswith(\"SCOUT_\"):\n             scout_name = setting.replace(\"SCOUT_\", \"\").lower()\n         else:\n@@ -51,6 +53,8 @@\n             # It was removed\n             scout_config.unset(scout_name)\n         else:\n+            if cast is not None:\n+                value = cast(value)\n             scout_config.set(**{scout_name: value})\n \n     def install_middleware(self):\n", "issue": "Support Django BASE_DIR being a pathlib.Path\nAs per [my blog post today](https://adamj.eu/tech/2020/03/16/use-pathlib-in-your-django-project/), this is changing in Django 3.1 but users may already be changing it now.\n", "before_files": [{"content": "# coding=utf-8\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom django.apps import AppConfig\nfrom django.conf import settings\nfrom django.test.signals import setting_changed\n\nimport scout_apm.core\nfrom scout_apm.core.config import scout_config\nfrom scout_apm.django.instruments.huey import ensure_huey_instrumented\nfrom scout_apm.django.instruments.sql import ensure_sql_instrumented\nfrom scout_apm.django.instruments.template import ensure_templates_instrumented\n\n\nclass ScoutApmDjangoConfig(AppConfig):\n    name = \"scout_apm\"\n    verbose_name = \"Scout Apm (Django)\"\n\n    def ready(self):\n        self.update_scout_config_from_django_settings()\n        setting_changed.connect(self.on_setting_changed)\n\n        # Finish installing the agent. If the agent isn't installed for any\n        # reason, return without installing instruments\n        installed = scout_apm.core.install()\n        if not installed:\n            return\n\n        self.install_middleware()\n\n        # Setup Instruments\n        ensure_huey_instrumented()\n        ensure_sql_instrumented()\n        ensure_templates_instrumented()\n\n    def update_scout_config_from_django_settings(self, **kwargs):\n        for name in dir(settings):\n            self.on_setting_changed(name)\n\n    def on_setting_changed(self, setting, **kwargs):\n        if setting == \"BASE_DIR\":\n            scout_name = \"application_root\"\n        elif setting.startswith(\"SCOUT_\"):\n            scout_name = setting.replace(\"SCOUT_\", \"\").lower()\n        else:\n            return\n\n        try:\n            value = getattr(settings, setting)\n        except AttributeError:\n            # It was removed\n            scout_config.unset(scout_name)\n        else:\n            scout_config.set(**{scout_name: value})\n\n    def install_middleware(self):\n        \"\"\"\n        Attempts to insert the ScoutApm middleware as the first middleware\n        (first on incoming requests, last on outgoing responses).\n        \"\"\"\n        from django.conf import settings\n\n        # If MIDDLEWARE is set, update that, with handling of tuple vs array forms\n        if getattr(settings, \"MIDDLEWARE\", None) is not None:\n            timing_middleware = \"scout_apm.django.middleware.MiddlewareTimingMiddleware\"\n            view_middleware = \"scout_apm.django.middleware.ViewTimingMiddleware\"\n\n            if isinstance(settings.MIDDLEWARE, tuple):\n                if timing_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE = (timing_middleware,) + settings.MIDDLEWARE\n                if view_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE = settings.MIDDLEWARE + (view_middleware,)\n            else:\n                if timing_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE.insert(0, timing_middleware)\n                if view_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE.append(view_middleware)\n\n        # Otherwise, we're doing old style middleware, do the same thing with\n        # the same handling of tuple vs array forms\n        else:\n            timing_middleware = (\n                \"scout_apm.django.middleware.OldStyleMiddlewareTimingMiddleware\"\n            )\n            view_middleware = \"scout_apm.django.middleware.OldStyleViewMiddleware\"\n\n            if isinstance(settings.MIDDLEWARE_CLASSES, tuple):\n                if timing_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES = (\n                        timing_middleware,\n                    ) + settings.MIDDLEWARE_CLASSES\n\n                if view_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES + (\n                        view_middleware,\n                    )\n            else:\n                if timing_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES.insert(0, timing_middleware)\n                if view_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES.append(view_middleware)\n", "path": "src/scout_apm/django/apps.py"}], "after_files": [{"content": "# coding=utf-8\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom django.apps import AppConfig\nfrom django.conf import settings\nfrom django.test.signals import setting_changed\n\nimport scout_apm.core\nfrom scout_apm.core.config import scout_config\nfrom scout_apm.django.instruments.huey import ensure_huey_instrumented\nfrom scout_apm.django.instruments.sql import ensure_sql_instrumented\nfrom scout_apm.django.instruments.template import ensure_templates_instrumented\n\n\nclass ScoutApmDjangoConfig(AppConfig):\n    name = \"scout_apm\"\n    verbose_name = \"Scout Apm (Django)\"\n\n    def ready(self):\n        self.update_scout_config_from_django_settings()\n        setting_changed.connect(self.on_setting_changed)\n\n        # Finish installing the agent. If the agent isn't installed for any\n        # reason, return without installing instruments\n        installed = scout_apm.core.install()\n        if not installed:\n            return\n\n        self.install_middleware()\n\n        # Setup Instruments\n        ensure_huey_instrumented()\n        ensure_sql_instrumented()\n        ensure_templates_instrumented()\n\n    def update_scout_config_from_django_settings(self, **kwargs):\n        for name in dir(settings):\n            self.on_setting_changed(name)\n\n    def on_setting_changed(self, setting, **kwargs):\n        cast = None\n        if setting == \"BASE_DIR\":\n            scout_name = \"application_root\"\n            cast = str\n        elif setting.startswith(\"SCOUT_\"):\n            scout_name = setting.replace(\"SCOUT_\", \"\").lower()\n        else:\n            return\n\n        try:\n            value = getattr(settings, setting)\n        except AttributeError:\n            # It was removed\n            scout_config.unset(scout_name)\n        else:\n            if cast is not None:\n                value = cast(value)\n            scout_config.set(**{scout_name: value})\n\n    def install_middleware(self):\n        \"\"\"\n        Attempts to insert the ScoutApm middleware as the first middleware\n        (first on incoming requests, last on outgoing responses).\n        \"\"\"\n        from django.conf import settings\n\n        # If MIDDLEWARE is set, update that, with handling of tuple vs array forms\n        if getattr(settings, \"MIDDLEWARE\", None) is not None:\n            timing_middleware = \"scout_apm.django.middleware.MiddlewareTimingMiddleware\"\n            view_middleware = \"scout_apm.django.middleware.ViewTimingMiddleware\"\n\n            if isinstance(settings.MIDDLEWARE, tuple):\n                if timing_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE = (timing_middleware,) + settings.MIDDLEWARE\n                if view_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE = settings.MIDDLEWARE + (view_middleware,)\n            else:\n                if timing_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE.insert(0, timing_middleware)\n                if view_middleware not in settings.MIDDLEWARE:\n                    settings.MIDDLEWARE.append(view_middleware)\n\n        # Otherwise, we're doing old style middleware, do the same thing with\n        # the same handling of tuple vs array forms\n        else:\n            timing_middleware = (\n                \"scout_apm.django.middleware.OldStyleMiddlewareTimingMiddleware\"\n            )\n            view_middleware = \"scout_apm.django.middleware.OldStyleViewMiddleware\"\n\n            if isinstance(settings.MIDDLEWARE_CLASSES, tuple):\n                if timing_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES = (\n                        timing_middleware,\n                    ) + settings.MIDDLEWARE_CLASSES\n\n                if view_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES + (\n                        view_middleware,\n                    )\n            else:\n                if timing_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES.insert(0, timing_middleware)\n                if view_middleware not in settings.MIDDLEWARE_CLASSES:\n                    settings.MIDDLEWARE_CLASSES.append(view_middleware)\n", "path": "src/scout_apm/django/apps.py"}]}