question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The "`text` missing" warning is technically not always accurate

See original GitHub issue

The _warn_text_if_missing() code is technically not always a valid warning.

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.models (UI component builders)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.rtm (RTM client)
  • slack_sdk.signature (Request Signature Verifier)

Although this warning is easy to suppress by setting SKIP_SLACK_SDK_WARNING in the env, the code is technically incorrect. 😄 Attachments are still supported (and used, since they have some advantages over Blocks). The issue is that attachments have a separate fallback property, and thus setting a top-level text property is technically not required, and the deprecation warning shouldn’t be logged.

From the docs: ScreenShot 2021-02-25-22 13 24

This can be fixed pretty easily with code like this:

def _warn_if_text_is_missing(endpoint: str, kwargs: Dict[str, Any]) -> None:
    attachments = kwargs.get("attachments")
    if attachments:
        if all([attachment.get("fallback") for attachment in attachments]):
            return
        missing = "fallback"
    else: 
        text = kwargs.get("text")
        if text and len(text.strip()) != 0:
            return
        missing = "text"
    message = (
        f"The `{missing}` argument is missing in the request payload for a {endpoint} call - "
        f"It's a best practice to always provide a `{missing}` argument when posting a message. "
        f"The `{missing}` argument is used in places where content cannot be rendered such as: "
        "system push notifications, assistive technology such as screen readers, etc."
    )
    # for unit tests etc.
    skip_deprecation = os.environ.get("SKIP_SLACK_SDK_WARNING")
    if skip_deprecation:
        return
    warnings.warn(message, UserWarning)

I realize this is minor since it’s just a cosmetic warning, but figured I’d mention it anyway.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eddygcommented, Aug 26, 2021

@agrawaltarun When using blocks, you should provide a top-level summary text item. (This is used for notifications, for example.) The warning you’re seeing is alerting you that it is missing.

e.g.:

json_body: {
   'user': 'toto',
   'text': "CRITICAL: Issue encountered during snapshot creation",
   'blocks': [
       {'type': 'section',
         'text': {'type': 'mrkdwn', 'text': 'CRITICAL: Issue encountered during snapshot creation on Host:'}
       },
       {'type': 'section',
         'text': ...
1reaction
agrawaltaruncommented, Aug 26, 2021

Thanks @seratch & @eddyg , this is helpful. The warning no longer appears post updating the request payload .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guidelines for Issuing AMBER Alerts - Office of Justice Programs
For an AMBER Alert to be effective in recovering a missing child, the law enforcement agency must have enough information to believe that...
Read more >
Enable or disable ActiveX settings in Office files
Click the File tab. In the Security Warning area, click Enable Content. Under Enable All Content, click Always enable this document's active content....
Read more >
Wireless Emergency Alerts | FEMA.gov
America's Missing: Broadcast Emergency Response (AMBER) Alerts are urgent bulletins issued in child-abduction cases.
Read more >
REDCap downtime: Tuesday, Dec. 8
All the missing data codes are displayed for reference at the top of the Codebook page. ... If an alert has the “Ensure...
Read more >
Dealing with missing data: Key assumptions and methods for ...
Its purpose is not to re-create the individual missing values as close as possible to the true ones, but to handle missing data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found