We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
I have an issue when I import the export json file
## Important Details

On-Premise w/ Docker, version 9.1.2

## Description

I have two servers with a sentry. There are several projects on the first server, and I would like to copy these projects to the clear second server.
I use the export/import commands. The export command works fine. However, when I run the import command, I get an error.

## Steps to Reproduce

1. Run command 'sentry export sentry_export.json' on the first server
2. Run command 'sentry import sentry_export.json' on the second server
3. Get an error

Good items to include here include:

`Traceback (most recent call last):
  File "/usr/local/bin/sentry", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/__init__.py", line 162, in main
    cli(prog_name=get_prog(), obj={}, max_content_width=100)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/decorators.py", line 36, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/runner/commands/backup.py", line 21, in import_
    for obj in serializers.deserialize("json", src, stream=True, use_natural_keys=True):
  File "/usr/local/lib/python2.7/site-packages/django/core/serializers/json.py", line 76, in Deserializer
    six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
  File "/usr/local/lib/python2.7/site-packages/django/core/serializers/json.py", line 70, in Deserializer
    for obj in PythonDeserializer(objects, **options):
  File "/usr/local/lib/python2.7/site-packages/django/core/serializers/python.py", line 140, in Deserializer
    data[field.name] = field.to_python(field_value)
  File "/usr/local/lib/python2.7/site-packages/sentry/db/models/fields/array.py", line 56, in to_python
    value = json.loads(value)
  File "/usr/local/lib/python2.7/site-packages/sentry/utils/json.py", line 111, in loads
    return _default_decoder.decode(value)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
django.core.serializers.base.DeserializationError: Expecting value: line 1 column 2 (char 1)`

### What you expected to happen

Import works fine too

### Possible Solution

[If you have an idea on how this could be solved include that detail here.]


--- 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/db/models/fields/array.py`
Content:
```
1 from django.db import models
2 
3 from sentry.db.models.utils import Creator
4 from sentry.utils import json
5 from sentry.utils.compat import map
6 
7 
8 # Adapted from django-pgfields
9 # https://github.com/lukesneeringer/django-pgfields/blob/master/django_pg/models/fields/array.py
10 class ArrayField(models.Field):
11     def __init__(self, of=models.TextField, **kwargs):
12         # Arrays in PostgreSQL are arrays of a particular type.
13         # Save the subtype in our field class.
14         if isinstance(of, type):
15             of = of()
16         self.of = of
17 
18         # Set "null" to True. Arrays don't have nulls, but null=True
19         # in the ORM amounts to nothing in SQL (whereas null=False
20         # corresponds to `NOT NULL`)
21         kwargs["null"] = True
22 
23         super().__init__(**kwargs)
24 
25     def contribute_to_class(self, cls, name):
26         """
27         Add a descriptor for backwards compatibility
28         with previous Django behavior.
29         """
30         super().contribute_to_class(cls, name)
31         setattr(cls, name, Creator(self))
32 
33     def db_type(self, connection):
34         return f"{self.of.db_type(connection)}[]"
35 
36     def get_internal_type(self):
37         return "TextField"
38 
39     def to_python(self, value):
40         if not value:
41             value = []
42         if isinstance(value, str):
43             value = json.loads(value)
44         return map(self.of.to_python, value)
45
```
--- 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/db/models/fields/array.py b/src/sentry/db/models/fields/array.py
--- a/src/sentry/db/models/fields/array.py
+++ b/src/sentry/db/models/fields/array.py
@@ -1,3 +1,5 @@
+import ast
+
 from django.db import models
 
 from sentry.db.models.utils import Creator
@@ -36,9 +38,26 @@
     def get_internal_type(self):
         return "TextField"
 
+    def get_prep_value(self, value):
+        """Iterate over each item in the array, and run it
+        through the `get_prep_value` of this array's type.
+        """
+        # If no valid value was given, return an empty list.
+        if not value:
+            return []
+
+        # Appropriately coerce each individual value within
+        # our array.
+        return [self.of.get_prep_value(item) for item in value]
+
     def to_python(self, value):
         if not value:
             value = []
         if isinstance(value, str):
-            value = json.loads(value)
+            try:
+                value = json.loads(value)
+            except json.JSONDecodeError:
+                # This is to accomodate the erronous exports pre 21.4.0
+                # See getsentry/sentry#23843 for more details
+                value = ast.literal_eval(value)
         return map(self.of.to_python, value)

{"golden_diff": "diff --git a/src/sentry/db/models/fields/array.py b/src/sentry/db/models/fields/array.py\n--- a/src/sentry/db/models/fields/array.py\n+++ b/src/sentry/db/models/fields/array.py\n@@ -1,3 +1,5 @@\n+import ast\n+\n from django.db import models\n \n from sentry.db.models.utils import Creator\n@@ -36,9 +38,26 @@\n     def get_internal_type(self):\n         return \"TextField\"\n \n+    def get_prep_value(self, value):\n+        \"\"\"Iterate over each item in the array, and run it\n+        through the `get_prep_value` of this array's type.\n+        \"\"\"\n+        # If no valid value was given, return an empty list.\n+        if not value:\n+            return []\n+\n+        # Appropriately coerce each individual value within\n+        # our array.\n+        return [self.of.get_prep_value(item) for item in value]\n+\n     def to_python(self, value):\n         if not value:\n             value = []\n         if isinstance(value, str):\n-            value = json.loads(value)\n+            try:\n+                value = json.loads(value)\n+            except json.JSONDecodeError:\n+                # This is to accomodate the erronous exports pre 21.4.0\n+                # See getsentry/sentry#23843 for more details\n+                value = ast.literal_eval(value)\n         return map(self.of.to_python, value)\n", "issue": "I have an issue when I import the export json file\n## Important Details\r\n\r\nOn-Premise w/ Docker, version 9.1.2\r\n\r\n## Description\r\n\r\nI have two servers with a sentry. There are several projects on the first server, and I would like to copy these projects to the clear second server.\r\nI use the export/import commands. The export command works fine. However, when I run the import command, I get an error.\r\n\r\n## Steps to Reproduce\r\n\r\n1. Run command 'sentry export sentry_export.json' on the first server\r\n2. Run command 'sentry import sentry_export.json' on the second server\r\n3. Get an error\r\n\r\nGood items to include here include:\r\n\r\n`Traceback (most recent call last):\r\n  File \"/usr/local/bin/sentry\", line 8, in <module>\r\n    sys.exit(main())\r\n  File \"/usr/local/lib/python2.7/site-packages/sentry/runner/__init__.py\", line 162, in main\r\n    cli(prog_name=get_prog(), obj={}, max_content_width=100)\r\n  File \"/usr/local/lib/python2.7/site-packages/click/core.py\", line 722, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/click/core.py\", line 697, in main\r\n    rv = self.invoke(ctx)\r\n  File \"/usr/local/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 \"/usr/local/lib/python2.7/site-packages/click/core.py\", line 895, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"/usr/local/lib/python2.7/site-packages/click/core.py\", line 535, in invoke\r\n    return callback(*args, **kwargs)\r\n  File \"/usr/local/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 \"/usr/local/lib/python2.7/site-packages/sentry/runner/decorators.py\", line 36, in inner\r\n    return ctx.invoke(f, *args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/click/core.py\", line 535, in invoke\r\n    return callback(*args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/sentry/runner/commands/backup.py\", line 21, in import_\r\n    for obj in serializers.deserialize(\"json\", src, stream=True, use_natural_keys=True):\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/serializers/json.py\", line 76, in Deserializer\r\n    six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/serializers/json.py\", line 70, in Deserializer\r\n    for obj in PythonDeserializer(objects, **options):\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/serializers/python.py\", line 140, in Deserializer\r\n    data[field.name] = field.to_python(field_value)\r\n  File \"/usr/local/lib/python2.7/site-packages/sentry/db/models/fields/array.py\", line 56, in to_python\r\n    value = json.loads(value)\r\n  File \"/usr/local/lib/python2.7/site-packages/sentry/utils/json.py\", line 111, in loads\r\n    return _default_decoder.decode(value)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/decoder.py\", line 370, in decode\r\n    obj, end = self.raw_decode(s)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/decoder.py\", line 400, in raw_decode\r\n    return self.scan_once(s, idx=_w(s, idx).end())\r\ndjango.core.serializers.base.DeserializationError: Expecting value: line 1 column 2 (char 1)`\r\n\r\n### What you expected to happen\r\n\r\nImport works fine too\r\n\r\n### Possible Solution\r\n\r\n[If you have an idea on how this could be solved include that detail here.]\r\n\n", "before_files": [{"content": "from django.db import models\n\nfrom sentry.db.models.utils import Creator\nfrom sentry.utils import json\nfrom sentry.utils.compat import map\n\n\n# Adapted from django-pgfields\n# https://github.com/lukesneeringer/django-pgfields/blob/master/django_pg/models/fields/array.py\nclass ArrayField(models.Field):\n    def __init__(self, of=models.TextField, **kwargs):\n        # Arrays in PostgreSQL are arrays of a particular type.\n        # Save the subtype in our field class.\n        if isinstance(of, type):\n            of = of()\n        self.of = of\n\n        # Set \"null\" to True. Arrays don't have nulls, but null=True\n        # in the ORM amounts to nothing in SQL (whereas null=False\n        # corresponds to `NOT NULL`)\n        kwargs[\"null\"] = True\n\n        super().__init__(**kwargs)\n\n    def contribute_to_class(self, cls, name):\n        \"\"\"\n        Add a descriptor for backwards compatibility\n        with previous Django behavior.\n        \"\"\"\n        super().contribute_to_class(cls, name)\n        setattr(cls, name, Creator(self))\n\n    def db_type(self, connection):\n        return f\"{self.of.db_type(connection)}[]\"\n\n    def get_internal_type(self):\n        return \"TextField\"\n\n    def to_python(self, value):\n        if not value:\n            value = []\n        if isinstance(value, str):\n            value = json.loads(value)\n        return map(self.of.to_python, value)\n", "path": "src/sentry/db/models/fields/array.py"}], "after_files": [{"content": "import ast\n\nfrom django.db import models\n\nfrom sentry.db.models.utils import Creator\nfrom sentry.utils import json\nfrom sentry.utils.compat import map\n\n\n# Adapted from django-pgfields\n# https://github.com/lukesneeringer/django-pgfields/blob/master/django_pg/models/fields/array.py\nclass ArrayField(models.Field):\n    def __init__(self, of=models.TextField, **kwargs):\n        # Arrays in PostgreSQL are arrays of a particular type.\n        # Save the subtype in our field class.\n        if isinstance(of, type):\n            of = of()\n        self.of = of\n\n        # Set \"null\" to True. Arrays don't have nulls, but null=True\n        # in the ORM amounts to nothing in SQL (whereas null=False\n        # corresponds to `NOT NULL`)\n        kwargs[\"null\"] = True\n\n        super().__init__(**kwargs)\n\n    def contribute_to_class(self, cls, name):\n        \"\"\"\n        Add a descriptor for backwards compatibility\n        with previous Django behavior.\n        \"\"\"\n        super().contribute_to_class(cls, name)\n        setattr(cls, name, Creator(self))\n\n    def db_type(self, connection):\n        return f\"{self.of.db_type(connection)}[]\"\n\n    def get_internal_type(self):\n        return \"TextField\"\n\n    def get_prep_value(self, value):\n        \"\"\"Iterate over each item in the array, and run it\n        through the `get_prep_value` of this array's type.\n        \"\"\"\n        # If no valid value was given, return an empty list.\n        if not value:\n            return []\n\n        # Appropriately coerce each individual value within\n        # our array.\n        return [self.of.get_prep_value(item) for item in value]\n\n    def to_python(self, value):\n        if not value:\n            value = []\n        if isinstance(value, str):\n            try:\n                value = json.loads(value)\n            except json.JSONDecodeError:\n                # This is to accomodate the erronous exports pre 21.4.0\n                # See getsentry/sentry#23843 for more details\n                value = ast.literal_eval(value)\n        return map(self.of.to_python, value)\n", "path": "src/sentry/db/models/fields/array.py"}]}