prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Missing 'org_results' data in production but has some in staging
  In file 'web/frontend/help_platform_base.py', method 'group_project_list' the org_results appears to be blank in our production environment.
  
  This manifests when we try to load the 'setup & installation' page
  <img width="734" alt="prod" src="https://cloud.githubusercontent.com/assets/4432296/9042832/2c773b94-39c6-11e5-9cc8-fa49f0a6f3ef.png">
  
  However, the same setup is in staging and appears to work, for certain random projects:
  <img width="737" alt="staging" src="https://cloud.githubusercontent.com/assets/4432296/9042839/37822d32-39c6-11e5-8c65-ddf6d700de75.png">
  
  In staging I ran 'update sentry_organizationmember_teams set is_active = 1;' and the projects all showed up in the dropdown. 
  
  We _did_ add a custom SSO implementation, so perhaps we missed a step on account creation?
  
  Since there is a "client keys" page, this isn't a show stopper but I'm worried that whatever is wrong could manifest in other ways that we haven't found yet.
  
  
  --- 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/web/frontend/help_platform_base.py`
  Content:
  ```
  1 from __future__ import absolute_import
  2 
  3 from django.db.models import Q
  4 from itertools import groupby
  5 
  6 from sentry.models import Project, ProjectKey
  7 from sentry.web.frontend.base import BaseView
  8 
  9 
  10 class HelpPlatformBaseView(BaseView):
  11     auth_required = False
  12 
  13     def get_project_list(self, user):
  14         return list(Project.objects.filter(
  15             Q(organization__member_set__has_global_access=True, organization__member_set__user=user)
  16             | Q(team__organizationmember__user=user)
  17         ).exclude(
  18             team__organizationmemberteam__is_active=False,
  19         ).select_related('team', 'organization').order_by('organization', 'team').distinct())
  20 
  21     def group_project_list(self, project_list):
  22         results = []
  23         for org, org_project_list in groupby(project_list, key=lambda x: x.organization):
  24             org_results = []
  25             for team, team_project_list in groupby(list(org_project_list), key=lambda x: x.team):
  26                 org_results.append((team, list(team_project_list)))
  27             results.append((org, org_results))
  28         return results
  29 
  30     def get_key(self, project):
  31         try:
  32             key = ProjectKey.objects.filter(project=project)[0]
  33         except IndexError:
  34             key = None
  35         return key
  36 
  37     def convert_args(self, request, *args, **kwargs):
  38         try:
  39             pid = int(request.GET.get('pid', request.session.get('pid', 0)))
  40         except (TypeError, ValueError):
  41             pid = None
  42 
  43         if request.user.is_authenticated():
  44             project_list = self.get_project_list(request.user)
  45         else:
  46             project_list = []
  47 
  48         if pid:
  49             for project in project_list:
  50                 if pid == project.id:
  51                     selected_project = project
  52                     break
  53             else:
  54                 selected_project = None
  55         else:
  56             selected_project = None
  57 
  58         if selected_project:
  59             request.session['pid'] = selected_project.id
  60 
  61         kwargs['project_list'] = project_list
  62         kwargs['selected_project'] = selected_project
  63 
  64         return (args, kwargs)
  65 
  66     def get_context_data(self, request, project_list, selected_project, **kwargs):
  67         context = super(HelpPlatformBaseView, self).get_context_data(request, **kwargs)
  68 
  69         if selected_project:
  70             key = self.get_key(selected_project)
  71         else:
  72             key = None
  73 
  74         if key:
  75             dsn_private = key.dsn_private
  76             dsn_public = key.dsn_public
  77         else:
  78             dsn_private = None
  79             dsn_public = None
  80 
  81         context = {
  82             'selected_project': selected_project,
  83             'org_results': self.group_project_list(project_list),
  84             'dsn': dsn_private,
  85             'dsn_public': dsn_public,
  86 
  87         }
  88         return context
  89
  ```
  --- 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/src/sentry/web/frontend/help_platform_base.py b/src/sentry/web/frontend/help_platform_base.py
  --- a/src/sentry/web/frontend/help_platform_base.py
  +++ b/src/sentry/web/frontend/help_platform_base.py
  @@ -3,7 +3,7 @@
   from django.db.models import Q
   from itertools import groupby
   
  -from sentry.models import Project, ProjectKey
  +from sentry.models import OrganizationMemberTeam, Project, ProjectKey
   from sentry.web.frontend.base import BaseView
   
   
  @@ -15,8 +15,11 @@
               Q(organization__member_set__has_global_access=True, organization__member_set__user=user)
               | Q(team__organizationmember__user=user)
           ).exclude(
  -            team__organizationmemberteam__is_active=False,
  -        ).select_related('team', 'organization').order_by('organization', 'team').distinct())
  +            team__id__in=OrganizationMemberTeam.objects.filter(
  +                organizationmember__user=user,
  +                is_active=False
  +            ).values('team_id')
  +        ).select_related('team', 'organization').order_by('organization__name', 'team__name', 'name').distinct())
   
       def group_project_list(self, project_list):
           results = []
  
verification_info: {"golden_diff": "diff --git a/src/sentry/web/frontend/help_platform_base.py b/src/sentry/web/frontend/help_platform_base.py\n--- a/src/sentry/web/frontend/help_platform_base.py\n+++ b/src/sentry/web/frontend/help_platform_base.py\n@@ -3,7 +3,7 @@\n from django.db.models import Q\n from itertools import groupby\n \n-from sentry.models import Project, ProjectKey\n+from sentry.models import OrganizationMemberTeam, Project, ProjectKey\n from sentry.web.frontend.base import BaseView\n \n \n@@ -15,8 +15,11 @@\n             Q(organization__member_set__has_global_access=True, organization__member_set__user=user)\n             | Q(team__organizationmember__user=user)\n         ).exclude(\n-            team__organizationmemberteam__is_active=False,\n-        ).select_related('team', 'organization').order_by('organization', 'team').distinct())\n+            team__id__in=OrganizationMemberTeam.objects.filter(\n+                organizationmember__user=user,\n+                is_active=False\n+            ).values('team_id')\n+        ).select_related('team', 'organization').order_by('organization__name', 'team__name', 'name').distinct())\n \n     def group_project_list(self, project_list):\n         results = []\n", "issue": "Missing 'org_results' data in production but has some in staging\nIn file 'web/frontend/help_platform_base.py', method 'group_project_list' the org_results appears to be blank in our production environment.\n\nThis manifests when we try to load the 'setup & installation' page\n<img width=\"734\" alt=\"prod\" src=\"https://cloud.githubusercontent.com/assets/4432296/9042832/2c773b94-39c6-11e5-9cc8-fa49f0a6f3ef.png\">\n\nHowever, the same setup is in staging and appears to work, for certain random projects:\n<img width=\"737\" alt=\"staging\" src=\"https://cloud.githubusercontent.com/assets/4432296/9042839/37822d32-39c6-11e5-8c65-ddf6d700de75.png\">\n\nIn staging I ran 'update sentry_organizationmember_teams set is_active = 1;' and the projects all showed up in the dropdown. \n\nWe _did_ add a custom SSO implementation, so perhaps we missed a step on account creation?\n\nSince there is a \"client keys\" page, this isn't a show stopper but I'm worried that whatever is wrong could manifest in other ways that we haven't found yet.\n\n", "before_files": [{"content": "from __future__ import absolute_import\n\nfrom django.db.models import Q\nfrom itertools import groupby\n\nfrom sentry.models import Project, ProjectKey\nfrom sentry.web.frontend.base import BaseView\n\n\nclass HelpPlatformBaseView(BaseView):\n    auth_required = False\n\n    def get_project_list(self, user):\n        return list(Project.objects.filter(\n            Q(organization__member_set__has_global_access=True, organization__member_set__user=user)\n            | Q(team__organizationmember__user=user)\n        ).exclude(\n            team__organizationmemberteam__is_active=False,\n        ).select_related('team', 'organization').order_by('organization', 'team').distinct())\n\n    def group_project_list(self, project_list):\n        results = []\n        for org, org_project_list in groupby(project_list, key=lambda x: x.organization):\n            org_results = []\n            for team, team_project_list in groupby(list(org_project_list), key=lambda x: x.team):\n                org_results.append((team, list(team_project_list)))\n            results.append((org, org_results))\n        return results\n\n    def get_key(self, project):\n        try:\n            key = ProjectKey.objects.filter(project=project)[0]\n        except IndexError:\n            key = None\n        return key\n\n    def convert_args(self, request, *args, **kwargs):\n        try:\n            pid = int(request.GET.get('pid', request.session.get('pid', 0)))\n        except (TypeError, ValueError):\n            pid = None\n\n        if request.user.is_authenticated():\n            project_list = self.get_project_list(request.user)\n        else:\n            project_list = []\n\n        if pid:\n            for project in project_list:\n                if pid == project.id:\n                    selected_project = project\n                    break\n            else:\n                selected_project = None\n        else:\n            selected_project = None\n\n        if selected_project:\n            request.session['pid'] = selected_project.id\n\n        kwargs['project_list'] = project_list\n        kwargs['selected_project'] = selected_project\n\n        return (args, kwargs)\n\n    def get_context_data(self, request, project_list, selected_project, **kwargs):\n        context = super(HelpPlatformBaseView, self).get_context_data(request, **kwargs)\n\n        if selected_project:\n            key = self.get_key(selected_project)\n        else:\n            key = None\n\n        if key:\n            dsn_private = key.dsn_private\n            dsn_public = key.dsn_public\n        else:\n            dsn_private = None\n            dsn_public = None\n\n        context = {\n            'selected_project': selected_project,\n            'org_results': self.group_project_list(project_list),\n            'dsn': dsn_private,\n            'dsn_public': dsn_public,\n\n        }\n        return context\n", "path": "src/sentry/web/frontend/help_platform_base.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nfrom django.db.models import Q\nfrom itertools import groupby\n\nfrom sentry.models import OrganizationMemberTeam, Project, ProjectKey\nfrom sentry.web.frontend.base import BaseView\n\n\nclass HelpPlatformBaseView(BaseView):\n    auth_required = False\n\n    def get_project_list(self, user):\n        return list(Project.objects.filter(\n            Q(organization__member_set__has_global_access=True, organization__member_set__user=user)\n            | Q(team__organizationmember__user=user)\n        ).exclude(\n            team__id__in=OrganizationMemberTeam.objects.filter(\n                organizationmember__user=user,\n                is_active=False\n            ).values('team_id')\n        ).select_related('team', 'organization').order_by('organization__name', 'team__name', 'name').distinct())\n\n    def group_project_list(self, project_list):\n        results = []\n        for org, org_project_list in groupby(project_list, key=lambda x: x.organization):\n            org_results = []\n            for team, team_project_list in groupby(list(org_project_list), key=lambda x: x.team):\n                org_results.append((team, list(team_project_list)))\n            results.append((org, org_results))\n        return results\n\n    def get_key(self, project):\n        try:\n            key = ProjectKey.objects.filter(project=project)[0]\n        except IndexError:\n            key = None\n        return key\n\n    def convert_args(self, request, *args, **kwargs):\n        try:\n            pid = int(request.GET.get('pid', request.session.get('pid', 0)))\n        except (TypeError, ValueError):\n            pid = None\n\n        if request.user.is_authenticated():\n            project_list = self.get_project_list(request.user)\n        else:\n            project_list = []\n\n        if pid:\n            for project in project_list:\n                if pid == project.id:\n                    selected_project = project\n                    break\n            else:\n                selected_project = None\n        else:\n            selected_project = None\n\n        if selected_project:\n            request.session['pid'] = selected_project.id\n\n        kwargs['project_list'] = project_list\n        kwargs['selected_project'] = selected_project\n\n        return (args, kwargs)\n\n    def get_context_data(self, request, project_list, selected_project, **kwargs):\n        context = super(HelpPlatformBaseView, self).get_context_data(request, **kwargs)\n\n        if selected_project:\n            key = self.get_key(selected_project)\n        else:\n            key = None\n\n        if key:\n            dsn_private = key.dsn_private\n            dsn_public = key.dsn_public\n        else:\n            dsn_private = None\n            dsn_public = None\n\n        context = {\n            'selected_project': selected_project,\n            'org_results': self.group_project_list(project_list),\n            'dsn': dsn_private,\n            'dsn_public': dsn_public,\n\n        }\n        return context\n", "path": "src/sentry/web/frontend/help_platform_base.py"}]}