Skip to content

Commit 81d8965

Browse files
Removes extraneous Nones in get
1 parent 6748c2d commit 81d8965

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/sentry/integrations/slack/integration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def send_notification(
115115
try:
116116
client.chat_postMessage(
117117
channel=target.resource_id,
118-
blocks=payload["blocks"],
118+
blocks=payload["blocks"] if len(payload["blocks"]) > 0 else None,
119119
text=payload["text"],
120-
attachments=payload.get("attachments", None),
120+
attachments=payload.get("attachments"),
121121
unfurl_links=False,
122122
unfurl_media=False,
123123
)
@@ -137,9 +137,9 @@ def send_notification_with_threading(
137137
)
138138
kwargs: dict[str, Any] = dict(
139139
channel=target.resource_id,
140-
blocks=payload["blocks"],
140+
blocks=payload["blocks"] if len(payload["blocks"]) > 0 else None,
141141
text=payload["text"],
142-
attachments=payload.get("attachments", None),
142+
attachments=payload.get("attachments"),
143143
unfurl_links=False,
144144
unfurl_media=False,
145145
)

src/sentry/notifications/platform/api/endpoints/internal_registered_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def serialize_slack_preview[T: NotificationData](
9999
for block in message.get("blocks", []):
100100
serialized_blocks.append(block.to_dict())
101101

102-
return {"blocks": serialized_blocks, "attachments": message.get("attachments", None)}
102+
return {"blocks": serialized_blocks, "attachments": message.get("attachments")}
103103

104104

105105
def serialize_discord_preview[T: NotificationData](

src/sentry/notifications/platform/slack/renderers/metric_alert.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import logging
4+
35
from sentry.incidents.models.incident import IncidentStatus
46
from sentry.integrations.messaging.types import LEVEL_TO_COLOR
57
from sentry.integrations.metric_alerts import get_status_text
@@ -16,6 +18,8 @@
1618
NotificationRenderedTemplate,
1719
)
1820

21+
logger = logging.getLogger(__name__)
22+
1923

2024
class SlackMetricAlertRenderer(NotificationRenderer[SlackRenderable]):
2125
provider_key = NotificationProviderKey.SLACK
@@ -47,6 +51,8 @@ def render[DataT: NotificationData](
4751
{"blocks": slack_body.get("blocks", []), "color": slack_body.get("color", "")}
4852
]
4953

54+
logger.info(f"attachment_blocks: {attachment_blocks}")
55+
5056
renderable = SlackRenderable(
5157
blocks=[],
5258
attachments=attachment_blocks,

tests/sentry/notifications/platform/slack/renderers/test_metric_alert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_render_produces_blocks(self) -> None:
9696
)
9797

9898
# Without a chart: exactly one section block
99-
assert result.get("attachments", None) is not None
99+
assert result.get("attachments") is not None
100100
attachments: list[Any] = result["attachments"]
101101
assert len(attachments) == 1
102102
blocks: list[Any] = attachments[0]["blocks"]
@@ -123,7 +123,7 @@ def test_render_includes_image_block_when_chart_url_set(self) -> None:
123123
rendered_template=self.rendered_template,
124124
)
125125

126-
assert result.get("attachments", None) is not None
126+
assert result.get("attachments") is not None
127127

128128
# With a chart: section block + image block
129129
blocks: list[Any] = result["attachments"][0]["blocks"]
@@ -140,7 +140,7 @@ def test_render_without_chart_url(self) -> None:
140140
rendered_template=self.rendered_template,
141141
)
142142

143-
assert result.get("attachments", None) is not None
143+
assert result.get("attachments") is not None
144144
attachments: list[Any] = result["attachments"]
145145
assert len(attachments) == 1
146146
blocks: list[Any] = attachments[0]["blocks"]

0 commit comments

Comments
 (0)