We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
sentry django send_fake_data errors out
## Important Details

How are you running Sentry?

* [ ] On-Premise docker [Version xyz]
* [ ] Saas (sentry.io)
* [x] Other [briefly describe your environment]
Development environment on macOS while working on sentry-plugins, with `sentry devserver`

## Description

When running `sentry django send_fake_data` a stacktrace is raised:

```
Traceback (most recent call last):
  File "MYPYTHONPATH/bin/sentry", line 11, in <module>
    load_entry_point('sentry', 'console_scripts', 'sentry')()
  File "MYPYTHONPATH/src/sentry/src/sentry/runner/__init__.py", line 161, in main
    cli(prog_name=get_prog(), obj={}, max_content_width=100)
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "MYPYTHONPATH/src/sentry/src/sentry/runner/decorators.py", line 36, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "MYPYTHONPATH/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "MYPYTHONPATH/src/sentry/src/sentry/runner/commands/django.py", line 25, in django
    execute_from_command_line(argv=[ctx.command_path] + list(management_args))
  File "MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "MYPYTHONPATH/src/sentry/src/sentry/management/commands/send_fake_data.py", line 75, in handle
    from raven.contrib.django.models import client
ImportError: No module named raven.contrib.django.models
```

## Steps to Reproduce

See above.

### What you expected to happen

Some fake data should magically appear!

### Possible Solution

Appears to be coming from this import:
https://github.com/getsentry/sentry/blob/317c65fbcd0f0b31a4e97c415bcf35256900a286/src/sentry/management/commands/send_fake_data.py#L75

Manually running `pip install raven` appears to solve it - no traceback appears, so I guess having raven installed, that solves the immediate issue.

However, I think that there's no events being sent anyhow - as perceived by this log:
```
[INFO] raven.contrib.django.client.DjangoClient: Raven is not configured (logging is disabled). Please see the documentation for more information. (message=u'Raven is not configured (logging is disabled). Please see the documentation for more information.')
Preparing to send events. Ctrl-C to exit.
```

I saw there's a push to go towards the unified python sdk - should this fix be overall done with that approach?


--- 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/sentry/management/commands/send_fake_data.py`
Content:
```
1 import datetime
2 import itertools
3 import random
4 import time
5 
6 from django.core.management.base import BaseCommand, CommandError
7 
8 
9 def funcs():
10     exceptions = itertools.cycle(
11         [
12             SyntaxError("foo must come before bar"),
13             ValueError("baz is not a valid choice"),
14             TypeError("NoneType cannot be coerced to bar"),
15             NotImplementedError("This feature is not implemented"),
16             ZeroDivisionError("Your math doesn't work"),
17             Exception("An unknown exception"),
18             KeyError("index does not exist"),
19         ]
20     )
21     loggers = itertools.cycle(["root", "foo", "foo.bar"])
22     emails = itertools.cycle(["foo@example.com", "bar@example.com", "baz@example.com"])
23     timestamp_max = int(datetime.timedelta(days=1).total_seconds())
24 
25     def exception(client):
26         timestamp = datetime.datetime.utcnow() - datetime.timedelta(
27             seconds=random.randint(0, timestamp_max)
28         )
29         try:
30             raise next(exceptions)
31         except Exception:
32             email = next(emails)
33             return client.captureException(
34                 data={
35                     "logger": next(loggers),
36                     "site": "web",
37                     "user": {"id": email, "email": email},
38                 },
39                 date=timestamp,
40             )
41 
42     return [exception]
43 
44 
45 class Command(BaseCommand):
46     help = "Sends fake data to the internal Sentry project"
47 
48     def add_arguments(self, parser):
49         parser.add_argument(
50             "--project", dest="project", help="project ID or organization-slug/project-slug"
51         )
52         parser.add_argument("--num", dest="num_events", type=int),
53 
54     def handle(self, **options):
55         from django.conf import settings
56         from raven.contrib.django.models import client
57         from sentry.models import Project
58 
59         if not options["project"]:
60             project = Project.objects.get(id=settings.SENTRY_PROJECT)
61         else:
62             if options["project"].isdigit():
63                 project = Project.objects.get(id=options["project"])
64             elif "/" in options["project"]:
65                 o_slug, p_slug = options["project"].split("/", 1)
66                 project = Project.objects.get(slug=p_slug, organization__slug=o_slug)
67             else:
68                 raise CommandError(
69                     "Project must be specified as organization-slug/project-slug or a project id"
70                 )
71 
72         client.project = project.id
73 
74         self.stdout.write("Preparing to send events. Ctrl-C to exit.")
75 
76         time.sleep(2)
77 
78         functions = funcs()
79 
80         if options["num_events"]:
81             max_events = options["num_events"]
82         else:
83             max_events = -1
84 
85         s = time.time()
86         r = 0
87         try:
88             while True:
89                 if r == max_events:
90                     break
91                 if options["verbosity"] > 1:
92                     self.stdout.write("Sending event..\n")
93                 random.choice(functions)(client)
94                 r += 1
95         except KeyboardInterrupt:
96             pass
97         finally:
98             total_time = time.time() - s
99             self.stdout.write("%d requests serviced in %.3fs\n" % (r, total_time))
100             if r:
101                 avg = total_time / r
102                 ravg = 1 / avg
103             else:
104                 avg = ravg = 0
105             self.stdout.write("avg of %.3fs/req, %d req/s\n" % (avg, ravg))
106
```
--- 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/sentry/management/commands/send_fake_data.py b/src/sentry/management/commands/send_fake_data.py
--- a/src/sentry/management/commands/send_fake_data.py
+++ b/src/sentry/management/commands/send_fake_data.py
@@ -28,16 +28,14 @@
         )
         try:
             raise next(exceptions)
-        except Exception:
+        except Exception as exc:
             email = next(emails)
-            return client.captureException(
-                data={
-                    "logger": next(loggers),
-                    "site": "web",
-                    "user": {"id": email, "email": email},
-                },
-                date=timestamp,
-            )
+            with client.configure_scope() as scope:
+                scope.user = {"id": email, "email": email}
+                scope.logger = next(loggers)
+                scope.site = "web"
+                scope.date = timestamp
+                return client.captureException(exc)
 
     return [exception]
 
@@ -53,7 +51,7 @@
 
     def handle(self, **options):
         from django.conf import settings
-        from raven.contrib.django.models import client
+        from sentry.app import client
         from sentry.models import Project
 
         if not options["project"]:

{"golden_diff": "diff --git a/src/sentry/management/commands/send_fake_data.py b/src/sentry/management/commands/send_fake_data.py\n--- a/src/sentry/management/commands/send_fake_data.py\n+++ b/src/sentry/management/commands/send_fake_data.py\n@@ -28,16 +28,14 @@\n         )\n         try:\n             raise next(exceptions)\n-        except Exception:\n+        except Exception as exc:\n             email = next(emails)\n-            return client.captureException(\n-                data={\n-                    \"logger\": next(loggers),\n-                    \"site\": \"web\",\n-                    \"user\": {\"id\": email, \"email\": email},\n-                },\n-                date=timestamp,\n-            )\n+            with client.configure_scope() as scope:\n+                scope.user = {\"id\": email, \"email\": email}\n+                scope.logger = next(loggers)\n+                scope.site = \"web\"\n+                scope.date = timestamp\n+                return client.captureException(exc)\n \n     return [exception]\n \n@@ -53,7 +51,7 @@\n \n     def handle(self, **options):\n         from django.conf import settings\n-        from raven.contrib.django.models import client\n+        from sentry.app import client\n         from sentry.models import Project\n \n         if not options[\"project\"]:\n", "issue": "sentry django send_fake_data errors out\n## Important Details\r\n\r\nHow are you running Sentry?\r\n\r\n* [ ] On-Premise docker [Version xyz]\r\n* [ ] Saas (sentry.io)\r\n* [x] Other [briefly describe your environment]\r\nDevelopment environment on macOS while working on sentry-plugins, with `sentry devserver`\r\n\r\n## Description\r\n\r\nWhen running `sentry django send_fake_data` a stacktrace is raised:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"MYPYTHONPATH/bin/sentry\", line 11, in <module>\r\n    load_entry_point('sentry', 'console_scripts', 'sentry')()\r\n  File \"MYPYTHONPATH/src/sentry/src/sentry/runner/__init__.py\", line 161, in main\r\n    cli(prog_name=get_prog(), obj={}, max_content_width=100)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/core.py\", line 722, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/core.py\", line 697, in main\r\n    rv = self.invoke(ctx)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/core.py\", line 1066, in invoke\r\n    return _process_result(sub_ctx.command.invoke(sub_ctx))\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/core.py\", line 895, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/core.py\", line 535, in invoke\r\n    return callback(*args, **kwargs)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/decorators.py\", line 17, in new_func\r\n    return f(get_current_context(), *args, **kwargs)\r\n  File \"MYPYTHONPATH/src/sentry/src/sentry/runner/decorators.py\", line 36, in inner\r\n    return ctx.invoke(f, *args, **kwargs)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/core.py\", line 535, in invoke\r\n    return callback(*args, **kwargs)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/click/decorators.py\", line 17, in new_func\r\n    return f(get_current_context(), *args, **kwargs)\r\n  File \"MYPYTHONPATH/src/sentry/src/sentry/runner/commands/django.py\", line 25, in django\r\n    execute_from_command_line(argv=[ctx.command_path] + list(management_args))\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/__init__.py\", line 399, in execute_from_command_line\r\n    utility.execute()\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/__init__.py\", line 392, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/base.py\", line 242, in run_from_argv\r\n    self.execute(*args, **options.__dict__)\r\n  File \"MYPYTHONPATH/lib/python2.7/site-packages/django/core/management/base.py\", line 285, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"MYPYTHONPATH/src/sentry/src/sentry/management/commands/send_fake_data.py\", line 75, in handle\r\n    from raven.contrib.django.models import client\r\nImportError: No module named raven.contrib.django.models\r\n```\r\n\r\n## Steps to Reproduce\r\n\r\nSee above.\r\n\r\n### What you expected to happen\r\n\r\nSome fake data should magically appear!\r\n\r\n### Possible Solution\r\n\r\nAppears to be coming from this import:\r\nhttps://github.com/getsentry/sentry/blob/317c65fbcd0f0b31a4e97c415bcf35256900a286/src/sentry/management/commands/send_fake_data.py#L75\r\n\r\nManually running `pip install raven` appears to solve it - no traceback appears, so I guess having raven installed, that solves the immediate issue.\r\n\r\nHowever, I think that there's no events being sent anyhow - as perceived by this log:\r\n```\r\n[INFO] raven.contrib.django.client.DjangoClient: Raven is not configured (logging is disabled). Please see the documentation for more information. (message=u'Raven is not configured (logging is disabled). Please see the documentation for more information.')\r\nPreparing to send events. Ctrl-C to exit.\r\n```\r\n\r\nI saw there's a push to go towards the unified python sdk - should this fix be overall done with that approach?\r\n\n", "before_files": [{"content": "import datetime\nimport itertools\nimport random\nimport time\n\nfrom django.core.management.base import BaseCommand, CommandError\n\n\ndef funcs():\n    exceptions = itertools.cycle(\n        [\n            SyntaxError(\"foo must come before bar\"),\n            ValueError(\"baz is not a valid choice\"),\n            TypeError(\"NoneType cannot be coerced to bar\"),\n            NotImplementedError(\"This feature is not implemented\"),\n            ZeroDivisionError(\"Your math doesn't work\"),\n            Exception(\"An unknown exception\"),\n            KeyError(\"index does not exist\"),\n        ]\n    )\n    loggers = itertools.cycle([\"root\", \"foo\", \"foo.bar\"])\n    emails = itertools.cycle([\"foo@example.com\", \"bar@example.com\", \"baz@example.com\"])\n    timestamp_max = int(datetime.timedelta(days=1).total_seconds())\n\n    def exception(client):\n        timestamp = datetime.datetime.utcnow() - datetime.timedelta(\n            seconds=random.randint(0, timestamp_max)\n        )\n        try:\n            raise next(exceptions)\n        except Exception:\n            email = next(emails)\n            return client.captureException(\n                data={\n                    \"logger\": next(loggers),\n                    \"site\": \"web\",\n                    \"user\": {\"id\": email, \"email\": email},\n                },\n                date=timestamp,\n            )\n\n    return [exception]\n\n\nclass Command(BaseCommand):\n    help = \"Sends fake data to the internal Sentry project\"\n\n    def add_arguments(self, parser):\n        parser.add_argument(\n            \"--project\", dest=\"project\", help=\"project ID or organization-slug/project-slug\"\n        )\n        parser.add_argument(\"--num\", dest=\"num_events\", type=int),\n\n    def handle(self, **options):\n        from django.conf import settings\n        from raven.contrib.django.models import client\n        from sentry.models import Project\n\n        if not options[\"project\"]:\n            project = Project.objects.get(id=settings.SENTRY_PROJECT)\n        else:\n            if options[\"project\"].isdigit():\n                project = Project.objects.get(id=options[\"project\"])\n            elif \"/\" in options[\"project\"]:\n                o_slug, p_slug = options[\"project\"].split(\"/\", 1)\n                project = Project.objects.get(slug=p_slug, organization__slug=o_slug)\n            else:\n                raise CommandError(\n                    \"Project must be specified as organization-slug/project-slug or a project id\"\n                )\n\n        client.project = project.id\n\n        self.stdout.write(\"Preparing to send events. Ctrl-C to exit.\")\n\n        time.sleep(2)\n\n        functions = funcs()\n\n        if options[\"num_events\"]:\n            max_events = options[\"num_events\"]\n        else:\n            max_events = -1\n\n        s = time.time()\n        r = 0\n        try:\n            while True:\n                if r == max_events:\n                    break\n                if options[\"verbosity\"] > 1:\n                    self.stdout.write(\"Sending event..\\n\")\n                random.choice(functions)(client)\n                r += 1\n        except KeyboardInterrupt:\n            pass\n        finally:\n            total_time = time.time() - s\n            self.stdout.write(\"%d requests serviced in %.3fs\\n\" % (r, total_time))\n            if r:\n                avg = total_time / r\n                ravg = 1 / avg\n            else:\n                avg = ravg = 0\n            self.stdout.write(\"avg of %.3fs/req, %d req/s\\n\" % (avg, ravg))\n", "path": "src/sentry/management/commands/send_fake_data.py"}], "after_files": [{"content": "import datetime\nimport itertools\nimport random\nimport time\n\nfrom django.core.management.base import BaseCommand, CommandError\n\n\ndef funcs():\n    exceptions = itertools.cycle(\n        [\n            SyntaxError(\"foo must come before bar\"),\n            ValueError(\"baz is not a valid choice\"),\n            TypeError(\"NoneType cannot be coerced to bar\"),\n            NotImplementedError(\"This feature is not implemented\"),\n            ZeroDivisionError(\"Your math doesn't work\"),\n            Exception(\"An unknown exception\"),\n            KeyError(\"index does not exist\"),\n        ]\n    )\n    loggers = itertools.cycle([\"root\", \"foo\", \"foo.bar\"])\n    emails = itertools.cycle([\"foo@example.com\", \"bar@example.com\", \"baz@example.com\"])\n    timestamp_max = int(datetime.timedelta(days=1).total_seconds())\n\n    def exception(client):\n        timestamp = datetime.datetime.utcnow() - datetime.timedelta(\n            seconds=random.randint(0, timestamp_max)\n        )\n        try:\n            raise next(exceptions)\n        except Exception as exc:\n            email = next(emails)\n            with client.configure_scope() as scope:\n                scope.user = {\"id\": email, \"email\": email}\n                scope.logger = next(loggers)\n                scope.site = \"web\"\n                scope.date = timestamp\n                return client.captureException(exc)\n\n    return [exception]\n\n\nclass Command(BaseCommand):\n    help = \"Sends fake data to the internal Sentry project\"\n\n    def add_arguments(self, parser):\n        parser.add_argument(\n            \"--project\", dest=\"project\", help=\"project ID or organization-slug/project-slug\"\n        )\n        parser.add_argument(\"--num\", dest=\"num_events\", type=int),\n\n    def handle(self, **options):\n        from django.conf import settings\n        from sentry.app import client\n        from sentry.models import Project\n\n        if not options[\"project\"]:\n            project = Project.objects.get(id=settings.SENTRY_PROJECT)\n        else:\n            if options[\"project\"].isdigit():\n                project = Project.objects.get(id=options[\"project\"])\n            elif \"/\" in options[\"project\"]:\n                o_slug, p_slug = options[\"project\"].split(\"/\", 1)\n                project = Project.objects.get(slug=p_slug, organization__slug=o_slug)\n            else:\n                raise CommandError(\n                    \"Project must be specified as organization-slug/project-slug or a project id\"\n                )\n\n        client.project = project.id\n\n        self.stdout.write(\"Preparing to send events. Ctrl-C to exit.\")\n\n        time.sleep(2)\n\n        functions = funcs()\n\n        if options[\"num_events\"]:\n            max_events = options[\"num_events\"]\n        else:\n            max_events = -1\n\n        s = time.time()\n        r = 0\n        try:\n            while True:\n                if r == max_events:\n                    break\n                if options[\"verbosity\"] > 1:\n                    self.stdout.write(\"Sending event..\\n\")\n                random.choice(functions)(client)\n                r += 1\n        except KeyboardInterrupt:\n            pass\n        finally:\n            total_time = time.time() - s\n            self.stdout.write(\"%d requests serviced in %.3fs\\n\" % (r, total_time))\n            if r:\n                avg = total_time / r\n                ravg = 1 / avg\n            else:\n                avg = ravg = 0\n            self.stdout.write(\"avg of %.3fs/req, %d req/s\\n\" % (avg, ravg))\n", "path": "src/sentry/management/commands/send_fake_data.py"}]}