diff --git a/src/sentry/sentry_apps/api/endpoints/sentry_app_installations.py b/src/sentry/sentry_apps/api/endpoints/sentry_app_installations.py index 6e3f80020103d0..d6a6ab09fdfff4 100644 --- a/src/sentry/sentry_apps/api/endpoints/sentry_app_installations.py +++ b/src/sentry/sentry_apps/api/endpoints/sentry_app_installations.py @@ -18,6 +18,7 @@ from sentry.sentry_apps.models.sentry_app import SentryApp from sentry.sentry_apps.models.sentry_app_installation import SentryAppInstallation from sentry.users.models.user import User +from sentry.users.services.user.model import RpcUser class SentryAppInstallationsSerializer(serializers.Serializer): @@ -91,9 +92,9 @@ def post(self, request: Request, organization) -> Response: sentry_app__slug=slug, organization_id=organization.id ) except SentryAppInstallation.DoesNotExist: - assert isinstance( - request.user, User - ), f"user must be authenticated to create a SentryAppInstallation, currently is {type(request.user)}" + assert isinstance(request.user, User) or isinstance( + request.user, RpcUser + ), "user must be authenticated to create a SentryAppInstallation" install = SentryAppInstallationCreator( organization_id=organization.id, slug=slug, notify=True ).run(user=request.user, request=request) diff --git a/src/sentry/sentry_apps/installations.py b/src/sentry/sentry_apps/installations.py index 777f91b6bffe30..9cf122a680c301 100644 --- a/src/sentry/sentry_apps/installations.py +++ b/src/sentry/sentry_apps/installations.py @@ -19,6 +19,7 @@ from sentry.sentry_apps.services.hook import hook_service from sentry.tasks.sentry_apps import installation_webhook from sentry.users.models.user import User +from sentry.users.services.user.model import RpcUser from sentry.utils import metrics @@ -100,7 +101,7 @@ class SentryAppInstallationCreator: slug: str notify: bool = True - def run(self, *, user: User, request: HttpRequest | None) -> SentryAppInstallation: + def run(self, *, user: User | RpcUser, request: HttpRequest | None) -> SentryAppInstallation: metrics.incr("sentry_apps.installation.attempt") with transaction.atomic(router.db_for_write(ApiGrant)): api_grant = self._create_api_grant() @@ -157,7 +158,7 @@ def audit(self, request: HttpRequest | None) -> None: data={"sentry_app": self.sentry_app.name}, ) - def record_analytics(self, user: User) -> None: + def record_analytics(self, user: User | RpcUser) -> None: analytics.record( "sentry_app.installed", user_id=user.id,