Skip to content

ref(app-platform): Backfill IntegrationFeature table #13548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/sentry/mediators/sentry_apps/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import six

from collections import Iterable
from django.db import IntegrityError, transaction

from sentry import analytics
from sentry.mediators import Mediator, Param
from sentry.models import (
AuditLogEntryEvent,
ApiApplication,
IntegrationFeature,
SentryApp,
SentryAppComponent,
User,
Expand All @@ -34,6 +36,7 @@ def call(self):
self.api_app = self._create_api_application()
self.sentry_app = self._create_sentry_app()
self._create_ui_components()
self._create_integration_feature()
return self.sentry_app

def _create_proxy_user(self):
Expand Down Expand Up @@ -75,6 +78,20 @@ def _create_ui_components(self):
schema=element,
)

def _create_integration_feature(self):
# sentry apps must have at least one feature
# defaults to 'integrations-api'
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong pattern. It also needs to be wrapped ina transaction block.

try:
    with transaction.atomic():
        IntegrationFeature.objects.create(...)
except IntegrityError:
    pass

And do you really need to log when this happens? This behavior is more like, "ensure this exists, but fail silently" kinda thing when we do it elsewhere. We never log this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole object's logic is run inside of a transaction. Every Mediators' is. https://github.com/getsentry/sentry/blob/master/src/sentry/mediators/mediator.py#L156-L164

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole mediator is wrapped in a transaction, so is it necessary to have it within that specific block too?

Also since this is in the creator, there really shouldn't be one that already exists - so if that does happen maybe I'd want to know?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole mediator is wrapped in a transaction, so is it necessary to have it within that specific block too?

Yes, it still needs a transaction. Technically a checkpoint. Otherwise, it'll break your other transaction and put it in an invalid state.

Also since this is in the creator, there really shouldn't be one that already exists - so if that does happen maybe I'd want to know?

That's your call, and just depends or your expectations.

with transaction.atomic():
IntegrationFeature.objects.create(
sentry_app=self.sentry_app,
)
except IntegrityError as e:
self.log(
sentry_app=self.sentry_app.slug,
error_message=e.message,
)

def audit(self):
from sentry.utils.audit import create_audit_entry
if self.request:
Expand Down
Loading