Skip to content

Conversation

@mgaeta
Copy link
Contributor

@mgaeta mgaeta commented Nov 2, 2021

This refactor adds unimplemented methods to the BaseNotification class so that we can use polymorphism instead of a long series of conditionals.

"style": action.style or "default",
"type": "button",
}
for action in actions
Copy link
Contributor

Choose a reason for hiding this comment

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

@mgaeta IMO, if we aren't going to have a class method as_slack, we should still make a method that replicates the functionality rather than embedding the mapping logic in SlackMessageBuilder

}
)
return buttons
def get_message_builder(klass: str) -> type[SlackNotificationsMessageBuilder]:
Copy link
Member

Choose a reason for hiding this comment

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

What is klass? I don't understand the variable name.

Copy link
Contributor Author

@mgaeta mgaeta Nov 3, 2021

Choose a reason for hiding this comment

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

In python, class is a reserved word. By convention when we have a variable that we'd want to call "class" we use "klass".

In /src/sentry/notifications/notifications/activity/note.py we reference the class we want to use by string:

class NoteActivityNotification(GroupActivityNotification):
    message_builder = "SlackNotificationsMessageBuilder"
    ...

This is because it's impossible to import the sentry.integrations.slack module in this file without causing a circular dependency. Once we're in the Slack module we can get the class we want:

def get_message_builder(klass: str) -> type[SlackNotificationsMessageBuilder]:
    return {
        "DigestNotificationMessageBuilder": DigestNotificationMessageBuilder,
        "IssueNotificationMessageBuilder": IssueNotificationMessageBuilder,
        "SlackNotificationsMessageBuilder": SlackNotificationsMessageBuilder,
    }[klass]

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, I knew class was reserved but hadn't seen klass.

Copy link
Member

Choose a reason for hiding this comment

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

I think the convention in python is usually cls actually, klass is a ruby-ism

See https://www.python.org/dev/peps/pep-0008/#function-and-method-arguments

@mgaeta mgaeta requested review from a team and ceorourke November 3, 2021 18:01
self,
) -> Mapping[ExternalProviders, Mapping[User, int]]:
users_by_provider = NotificationSetting.objects.get_notification_recipients(self.project)
) -> Mapping[ExternalProviders, Mapping[Team | User, int]]:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this hurts anything, but I also don't think a team would ever be notified about processing issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just needed the method signature to match the parent class to satisfy the type checker.



class SlackOrganizationRequestMessageBuilder(SlackNotificationsMessageBuilder):
def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

Hmm this is gonna need a rebase when Steve's PR is merged since he's adding to this file

@mgaeta mgaeta merged commit c2e2c23 into master Nov 5, 2021
@mgaeta mgaeta deleted the feat/api-2202-slack-digest-5 branch November 5, 2021 22:39
getsentry-bot added a commit that referenced this pull request Nov 5, 2021
This reverts commit c2e2c23.

Co-authored-by: scefali via Slack <scefali@sentry.io>
mgaeta pushed a commit that referenced this pull request Nov 8, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants