We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
AttributeError /api/0/organizations/{organization_slug}/sentry-apps/
## Important Details

How are you running Sentry?

<!-- Please pick one of the following -->
On-Premise w/ Docker, Sentry 21.1.0486d790, based on https://github.com/Rungutan/sentry-performance-monitoring

## Description

Opening of these sub items in "Organization" settings fails:
* Audit Log
* Integrations
* Developer settings

This seems to be the resulting issue in the "Internal" Sentry project:
```
AttributeError: 'NoneType' object has no attribute 'get_allowed_origins'
  File "sentry/api/base.py", line 124, in handle_exception
    response = super(Endpoint, self).handle_exception(exc)
  File "rest_framework/views.py", line 449, in handle_exception
    self.raise_uncaught_exception(exc)
  File "sentry/api/base.py", line 237, in dispatch
    response = handler(request, *args, **kwargs)
  File "sentry/api/bases/sentryapps.py", line 59, in wrapped
    return func(self, *args, **kwargs)
  File "sentry/api/endpoints/organization_sentry_apps.py", line 19, in get
    on_results=lambda x: serialize(x, request.user, access=request.access),
  File "sentry/api/base.py", line 330, in paginate
    results = on_results(cursor_result.results)
  File "sentry/api/endpoints/organization_sentry_apps.py", line 19, in <lambda>
    on_results=lambda x: serialize(x, request.user, access=request.access),
  File "sentry/api/serializers/base.py", line 45, in serialize
    return [serializer(o, attrs=attrs.get(o, {}), user=user, **kwargs) for o in objects]
  File "sentry/api/serializers/base.py", line 45, in <listcomp>
    return [serializer(o, attrs=attrs.get(o, {}), user=user, **kwargs) for o in objects]
  File "sentry/api/serializers/base.py", line 60, in __call__
    return self.serialize(obj, attrs, user, **kwargs)
  File "sentry/api/serializers/models/sentry_app.py", line 31, in serialize
    "allowedOrigins": obj.application.get_allowed_origins(),
```

Last SQL before exception

```
SELECT "sentry_organization"."id", "sentry_organization"."name", "sentry_organization"."slug", "sentry_organization"."status", "sentry_organization"."date_added", "sentry_organization"."default_role", "sentry_organization"."flags" FROM "sentry_organization" WHERE "sentry_organization"."id" = %s
```

### What you expected to happen
Menus should work.

### 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/api/endpoints/organization_sentry_apps.py`
Content:
```
1 from sentry.api.bases import OrganizationEndpoint, add_integration_platform_metric_tag
2 from sentry.api.paginator import OffsetPaginator
3 from sentry.api.serializers import serialize
4 from sentry.models import SentryApp
5 
6 
7 class OrganizationSentryAppsEndpoint(OrganizationEndpoint):
8     @add_integration_platform_metric_tag
9     def get(self, request, organization):
10         queryset = SentryApp.objects.filter(owner=organization)
11 
12         return self.paginate(
13             request=request,
14             queryset=queryset,
15             order_by="-date_added",
16             paginator_cls=OffsetPaginator,
17             on_results=lambda x: serialize(x, request.user, access=request.access),
18         )
19
```
--- 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/api/endpoints/organization_sentry_apps.py b/src/sentry/api/endpoints/organization_sentry_apps.py
--- a/src/sentry/api/endpoints/organization_sentry_apps.py
+++ b/src/sentry/api/endpoints/organization_sentry_apps.py
@@ -7,7 +7,7 @@
 class OrganizationSentryAppsEndpoint(OrganizationEndpoint):
     @add_integration_platform_metric_tag
     def get(self, request, organization):
-        queryset = SentryApp.objects.filter(owner=organization)
+        queryset = SentryApp.objects.filter(owner=organization, application__isnull=False)
 
         return self.paginate(
             request=request,

{"golden_diff": "diff --git a/src/sentry/api/endpoints/organization_sentry_apps.py b/src/sentry/api/endpoints/organization_sentry_apps.py\n--- a/src/sentry/api/endpoints/organization_sentry_apps.py\n+++ b/src/sentry/api/endpoints/organization_sentry_apps.py\n@@ -7,7 +7,7 @@\n class OrganizationSentryAppsEndpoint(OrganizationEndpoint):\n     @add_integration_platform_metric_tag\n     def get(self, request, organization):\n-        queryset = SentryApp.objects.filter(owner=organization)\n+        queryset = SentryApp.objects.filter(owner=organization, application__isnull=False)\n \n         return self.paginate(\n             request=request,\n", "issue": "AttributeError /api/0/organizations/{organization_slug}/sentry-apps/\n## Important Details\r\n\r\nHow are you running Sentry?\r\n\r\n<!-- Please pick one of the following -->\r\nOn-Premise w/ Docker, Sentry 21.1.0486d790, based on https://github.com/Rungutan/sentry-performance-monitoring\r\n\r\n## Description\r\n\r\nOpening of these sub items in \"Organization\" settings fails:\r\n* Audit Log\r\n* Integrations\r\n* Developer settings\r\n\r\nThis seems to be the resulting issue in the \"Internal\" Sentry project:\r\n```\r\nAttributeError: 'NoneType' object has no attribute 'get_allowed_origins'\r\n  File \"sentry/api/base.py\", line 124, in handle_exception\r\n    response = super(Endpoint, self).handle_exception(exc)\r\n  File \"rest_framework/views.py\", line 449, in handle_exception\r\n    self.raise_uncaught_exception(exc)\r\n  File \"sentry/api/base.py\", line 237, in dispatch\r\n    response = handler(request, *args, **kwargs)\r\n  File \"sentry/api/bases/sentryapps.py\", line 59, in wrapped\r\n    return func(self, *args, **kwargs)\r\n  File \"sentry/api/endpoints/organization_sentry_apps.py\", line 19, in get\r\n    on_results=lambda x: serialize(x, request.user, access=request.access),\r\n  File \"sentry/api/base.py\", line 330, in paginate\r\n    results = on_results(cursor_result.results)\r\n  File \"sentry/api/endpoints/organization_sentry_apps.py\", line 19, in <lambda>\r\n    on_results=lambda x: serialize(x, request.user, access=request.access),\r\n  File \"sentry/api/serializers/base.py\", line 45, in serialize\r\n    return [serializer(o, attrs=attrs.get(o, {}), user=user, **kwargs) for o in objects]\r\n  File \"sentry/api/serializers/base.py\", line 45, in <listcomp>\r\n    return [serializer(o, attrs=attrs.get(o, {}), user=user, **kwargs) for o in objects]\r\n  File \"sentry/api/serializers/base.py\", line 60, in __call__\r\n    return self.serialize(obj, attrs, user, **kwargs)\r\n  File \"sentry/api/serializers/models/sentry_app.py\", line 31, in serialize\r\n    \"allowedOrigins\": obj.application.get_allowed_origins(),\r\n```\r\n\r\nLast SQL before exception\r\n\r\n```\r\nSELECT \"sentry_organization\".\"id\", \"sentry_organization\".\"name\", \"sentry_organization\".\"slug\", \"sentry_organization\".\"status\", \"sentry_organization\".\"date_added\", \"sentry_organization\".\"default_role\", \"sentry_organization\".\"flags\" FROM \"sentry_organization\" WHERE \"sentry_organization\".\"id\" = %s\r\n```\r\n\r\n### What you expected to happen\r\nMenus should work.\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 sentry.api.bases import OrganizationEndpoint, add_integration_platform_metric_tag\nfrom sentry.api.paginator import OffsetPaginator\nfrom sentry.api.serializers import serialize\nfrom sentry.models import SentryApp\n\n\nclass OrganizationSentryAppsEndpoint(OrganizationEndpoint):\n    @add_integration_platform_metric_tag\n    def get(self, request, organization):\n        queryset = SentryApp.objects.filter(owner=organization)\n\n        return self.paginate(\n            request=request,\n            queryset=queryset,\n            order_by=\"-date_added\",\n            paginator_cls=OffsetPaginator,\n            on_results=lambda x: serialize(x, request.user, access=request.access),\n        )\n", "path": "src/sentry/api/endpoints/organization_sentry_apps.py"}], "after_files": [{"content": "from sentry.api.bases import OrganizationEndpoint, add_integration_platform_metric_tag\nfrom sentry.api.paginator import OffsetPaginator\nfrom sentry.api.serializers import serialize\nfrom sentry.models import SentryApp\n\n\nclass OrganizationSentryAppsEndpoint(OrganizationEndpoint):\n    @add_integration_platform_metric_tag\n    def get(self, request, organization):\n        queryset = SentryApp.objects.filter(owner=organization, application__isnull=False)\n\n        return self.paginate(\n            request=request,\n            queryset=queryset,\n            order_by=\"-date_added\",\n            paginator_cls=OffsetPaginator,\n            on_results=lambda x: serialize(x, request.user, access=request.access),\n        )\n", "path": "src/sentry/api/endpoints/organization_sentry_apps.py"}]}