-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(ACI): Fix adding sentry app action to a workflow #103790
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
base: master
Are you sure you want to change the base?
Conversation
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
| "sentryAppIdentifier": SentryAppIdentifier.SENTRY_APP_INSTALLATION_UUID, | ||
| "targetIdentifier": self.sentry_app_installation.uuid, | ||
| "targetType": ActionType.SENTRY_APP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ameliahsu I was only able to get this test to pass if I used this data which differs from what was passed in https://sentry.sentry.io/issues/6980690322 which was
{
"sentry_app_identifier":"'sentry_app_id'",
"target_identifier":"'72013'",
"target_type":"'sentry_app'"
}
Do you know if the data in the Sentry issue is what's expected to be passed all the time or only sometimes? I'm not sure when we pass one versus the other, but if we set sentryAppIdentifier to "sentry_app" instead of "sentry_app_installation" (SentryAppIdentifier.SENTRY_APP_INSTALLATION_UUID) we go down a slightly different code path and set sentryAppInstallationUuid to None (code here) which leads to a SentryAppInstallation.DoesNotExist error (here).
I truly don't know if this is a bug or how it's intended to work, but it doesn't currently work if you do not pass the installation data. I did verify that even an internal unpublished sentry app has an installation object, so maybe it's intended for us to always pass that data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GabeVillalobos might be able to help here, i believe some existing app actions use the sentry app UUID instead of the sentry app ID, which is why we have to specify sentry_app_identifier? but we would like for all newly created actions going forward to use sentry app ID. not sure if that's why we throw an error tho 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short answer here is that sentry_app_installation is some legacy data we need to migrate away from and the front end will be passing sentry_app_id for new actions. I updated the code to support both until we can run the migration so that old action with the uuid can be updated.
src/sentry/notifications/notification_action/action_handler_registry/sentry_app_handler.py
Outdated
Show resolved
Hide resolved
src/sentry/notifications/notification_action/action_validation.py
Outdated
Show resolved
Hide resolved
| if settings: | ||
| try: | ||
| # Only call creator for Sentry Apps with UI Components (settings) for actions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this logic from how we do it today - in project_rule_details.py and project_rules.py we call trigger_sentry_app_action_creators_for_issues (here) which skips over the validation if there is no UI component
| except SentryAppInstallation.DoesNotExist: | ||
| return None | ||
|
|
||
| def get_installation_by_uuid( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need this temporarily until we can migrate the action data to not have the installation uuid
2966483 to
0ddf637
Compare
20f0117 to
f78da0a
Compare
933836f to
4472102
Compare
cathteng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good
| installation = app_service.get_installation_by_sentry_app_id( | ||
| sentry_app_id=int(target_identifier), organization_id=self.organization.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new RPC function will need to be deployed in a separate PR from the PR where you use it
| return self.validated_data | ||
| except SentryAppBaseError as e: | ||
| raise ValidationError(e.message) from e | ||
| return self.validated_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be updating the validated data here to only save sentry app actions with sentry_app_identifier = "sentry_app_id"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have actions with the uuid saved in the db today so we don't want to block being able to update those. After we run the migration maybe part of the cleanup can be enforcing only that identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If somebody is trying to update an action with a uuid we could update that action to save it with the sentry app id so we don't have any more actions being saved with uuid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated 👍
tests/sentry/workflow_engine/endpoints/validators/actions/test_sentry_app.py
Outdated
Show resolved
Hide resolved
src/sentry/notifications/notification_action/action_validation.py
Outdated
Show resolved
Hide resolved
tests/sentry/workflow_engine/endpoints/test_organization_workflow_index.py
Outdated
Show resolved
Hide resolved
| installations = None | ||
| installation = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is typing gonna complain this needs to be RpcSentryAppInstallation | None = None?
tests/sentry/workflow_engine/endpoints/validators/actions/test_sentry_app.py
Show resolved
Hide resolved
tests/sentry/workflow_engine/endpoints/validators/actions/test_sentry_app.py
Outdated
Show resolved
Hide resolved
| ) | ||
| else: | ||
| installations = app_service.get_many( | ||
| filter=dict(app_ids=[int(target_identifier)], organization_id=self.organization.id) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good thing it is a number
| ) | ||
| else: | ||
| installations = app_service.get_many( | ||
| filter=dict(app_ids=[int(target_identifier)], organization_id=self.organization.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unhandled ValueError when converting target identifier to int
When sentry_app_identifier is SENTRY_APP_ID, the code converts target_identifier to an integer without error handling. If a user passes a non-numeric string (like a UUID) as the target_identifier, this will raise an unhandled ValueError instead of returning a proper validation error, causing a 500 error rather than a user-friendly 400 validation error.
Fixes adding and updating sentry app actions on a workflow and requires
settingsto be passed for a sentry app action if it has a UI component. If it has no component,settingsdoes not need to be passed.Adds support for a
target_typeof eithersentry_app_idorsentry_app_installation_uuiduntil we can migrate the data to only havesentry_app_id.Add tests for adding and updating sentry app actions.
Fixes https://sentry.sentry.io/issues/6980690322