Skip to content

Commit 0d23857

Browse files
mar3mar3seratch
andauthored
Fix #1302 by updating the warning logs in WebClient to be consistent with Node SDK (#1303)
Co-authored-by: Kazuhiro Sera <[email protected]>
1 parent 46ece5e commit 0d23857

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

slack_sdk/web/internal_utils.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -255,38 +255,39 @@ def _warn_if_text_or_attachment_fallback_is_missing(endpoint: str, kwargs: Dict[
255255
if skip_deprecation:
256256
return
257257

258-
# At this point, at a minimum, text argument is missing. Warn the user about this.
259-
message = (
258+
# if text argument is missing, Warn the user about this.
259+
# However, do not warn if a fallback field exists for all attachments, since this can be substituted.
260+
missing_text_message = (
260261
f"The top-level `text` argument is missing in the request payload for a {endpoint} call - "
261262
f"It's a best practice to always provide a `text` argument when posting a message. "
262263
f"The `text` argument is used in places where content cannot be rendered such as: "
263264
"system push notifications, assistive technology such as screen readers, etc."
264265
)
265-
warnings.warn(message, UserWarning)
266+
267+
# https://api.slack.com/reference/messaging/attachments
268+
# Check if the fallback field exists for all the attachments
269+
# Not all attachments have a fallback property; warn about this too!
270+
missing_fallback_message = (
271+
f"Additionally, the attachment-level `fallback` argument is missing in the request payload for a {endpoint} call"
272+
" - To avoid this warning, it is recommended to always provide a top-level `text` argument when posting a"
273+
" message. Alternatively you can provide an attachment-level `fallback` argument, though this is now considered"
274+
" a legacy field (see https://api.slack.com/reference/messaging/attachments#legacy_fields for more details)."
275+
)
266276

267277
# Additionally, specifically for attachments, there is a legacy field available at the attachment level called `fallback`
268278
# Even with a missing text, one can provide a `fallback` per attachment.
269279
# More details here: https://api.slack.com/reference/messaging/attachments#legacy_fields
270280
attachments = kwargs.get("attachments")
271281
# Note that this method does not verify attachments
272282
# if the value is already serialized as a single str value.
273-
if (
274-
attachments is not None
275-
and isinstance(attachments, list)
276-
and not all(
283+
if attachments is not None and isinstance(attachments, list):
284+
if not all(
277285
[isinstance(attachment, dict) and len(attachment.get("fallback", "").strip()) > 0 for attachment in attachments]
278-
)
279-
):
280-
# https://api.slack.com/reference/messaging/attachments
281-
# Check if the fallback field exists for all the attachments
282-
# Not all attachments have a fallback property; warn about this too!
283-
message = (
284-
f"Additionally, the attachment-level `fallback` argument is missing in the request payload for a {endpoint} call"
285-
f" - To avoid this warning, it is recommended to always provide a top-level `text` argument when posting a"
286-
f" message. Alternatively you can provide an attachment-level `fallback` argument, though this is now considered"
287-
f" a legacy field (see https://api.slack.com/reference/messaging/attachments#legacy_fields for more details)."
288-
)
289-
warnings.warn(message, UserWarning)
286+
):
287+
warnings.warn(missing_text_message, UserWarning)
288+
warnings.warn(missing_fallback_message, UserWarning)
289+
else:
290+
warnings.warn(missing_text_message, UserWarning)
290291

291292

292293
def _build_unexpected_body_error_message(body: str) -> str:

0 commit comments

Comments
 (0)