slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno
https://api.slack.com/automation
MIT License
168 stars 28 forks source link

[BUG] Datastore not allowing me to query by boolean field. #385

Open jpaulgale opened 6 days ago

jpaulgale commented 6 days ago

The deno-slack versions

"deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.14.2/",
"deno-slack-api/": "https://deno.land/x/deno_slack_api@2.8.0/"

Deno runtime version

deno 1.46.3 (stable, release, aarch64-apple-darwin)
v8 12.9.202.5-rusty
typescript 5.5.2

OS info

ProductName:        macOS
ProductVersion:     14.6.1
BuildVersion:       23G93
Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030

Describe the bug

Datastore is not allowing me to query by a boolean field.

Steps to reproduce

Here is the datastore file

import { DefineDatastore, Schema } from "deno-slack-sdk/mod.ts";

export const KudosDatastore = DefineDatastore({
  name: "kudos_data",
  primary_key: "id",
  attributes: {
    id: {
      type: Schema.types.string,
    },
    kudos_recipients: {
      type: Schema.types.string,
    },
    kudos_reason: {
      type: Schema.types.string,
    },
    submitted_by: {
      type: Schema.types.string,
    },
    submitted_at: {
      type: Schema.slack.types.timestamp,
    },
    shared_on_channel: {
      type: Schema.types.boolean,
    },
  },
});

And the contents of that datastore

slack datastore query '{
  "datastore": "kudos_data"
}'
? Select a team nameofourteam TCXXXXXX
? Choose an app environment Deployed A0XXXXXX
πŸŽ‰  Retrieved 3 items from datastore: kudos_data

{
  "id": "90bd9f75-235e-4a0b-b047-c0868cfc1a7e",
  "kudos_reason": "For building this app for us!",
  "kudos_recipients": "U0XXXXXX",
  "shared_on_channel": false,
  "submitted_at": 1732312534,
  "submitted_by": "U02XXXXXX"
}

{
  "id": "325ac455-6258-4ae1-865b-b90e5f1952ae",
  "kudos_reason": "Creating the airtable base!",
  "kudos_recipients": "U02BFQ59Q67",
  "shared_on_channel": false,
  "submitted_at": 1732313613,
  "submitted_by": "U01XXXXXX"
}

{
  "id": "c098295d-6ec9-4ba5-9f70-275c5bc6ce11",
  "kudos_reason": "805pm rockin the kasbah",
  "kudos_recipients": "U02BFQ59Q67",
  "shared_on_channel": false,
  "submitted_at": 1732323934,
  "submitted_by": "U01XXXXXX"
}

Expected result

I expect a query for shared_on_channel = false to return all three records

Actual result

When I try to filter by

"shared_on_channel" = false

slack datastore query '{
  "datastore": "kudos_data",
  "expression": "#shared = :false_value",
  "expression_attributes": {"#shared": "shared_on_channel"},
  "expression_values": {":false_value": false}
}'
? Select a team nameofourteam TCXXXXXXX
? Choose an app environment Deployed A07XXXXXX
Check /Users/paulgale/.slack/logs/slack-debug-20241123.log for error logs
The following error was returned by the apps.datastore.query Slack API method

🚫 An error occurred while accessing your datastore (datastore_error)
   InternalServerError: An InternalServerError occurred (datastore_query_error)
   Source: /datastore/kudos_data
WilliamBergamin commented 3 days ago

Hi @jpaulgale thanks for writing πŸ’―

I was able to reproduce this behavior, but I think this may be an issue with the CLI and not the SDK

I suspect some sort of JSON conversion is preventing boolean values like false or true from being passed to the dynamoDB properly πŸ€”

@mwbrooks would you be able to confirm if this is a CLI issue?

mwbrooks commented 3 days ago

Thanks for tagging me @WilliamBergamin πŸ™‡πŸ» and big props to @jpaulgale for the code samples πŸ‘ŒπŸ»

I was also able to reproduce the issue. πŸŽ‰

I think this a Slack API issue with /api/apps.datastore.query because I'm seeing the same error using the SDK and CLI.

Slack CLI:

Using the --verbose flag, it looks like the CLI is parsing the query correctly based on the API Request Body and the API Response is an InternalServerError:

$ slack datastore query '{ "datastore": "kudos_data", "expression": "#shared = :false_value", "expression_attributes": {"#shared": "shared_on_channel"}, "expression_values": {":false_value": false} }' --verbose

# [2024-11-25 13:31:44] HTTP Request: POST https://slack.com/api/apps.datastore.query HTTP/1.1
# HTTP Request Body:
# {"datastore":"kudos_data","app_id":"A082EED55SP","expression":"#shared = :false_value","expression_attributes": 
# {"#shared":"shared_on_channel"},"expression_values":{":false_value":false}}

# [2024-11-25 13:31:45] HTTP Response Status: HTTP/1.1 200 OK
# HTTP Response Body:
# {"ok":false,"error":"datastore_error","errors":[{"code":"datastore_query_error","message":"InternalServerError: An 
# InternalServerError occurred","pointer":"\/datastore\/kudos_data"}]}

Slack Deno SDK:

I tried Datastore Query using SDK by adding it to a Workflow Function and I receive a similar API Error when I view the activity logs:

    const result = await client.apps.datastore.query({
      "datastore": "kudos_data",
      "expression": "#shared = :false_value",
      "expression_attributes": { "#shared": "shared_on_channel" },
      "expression_values": { ":false_value": false },
    });

    console.log("Datastore Query Result:");
    console.log(result);
$ slack activity -t

# 2024-11-25 13:46:13 [error] [Datastore:kudos_data] (Trace=Tr082EGB0KSP) Datastore query failed with 
# '{"expression":"#shared = :false_value","expression_attributes":{"#shared":"shared_on_channel"},"expression_values":
# {":false_value":false},"limit":100,"cursor":""}'
# 
# InternalServerError: An InternalServerError occurred
# 
#        Datastore Query Result:
#        {
#          toFetchResponse: [Function: toFetchResponse],
#          ok: false,
#          error: "datastore_error",
#          errors: [
#            {
#              code: "datastore_query_error",
#              message: "InternalServerError: An InternalServerError occurred",
#              pointer: "/datastore/kudos_data"
#            }
#          ]
#        }

@WilliamBergamin I think we'll have to look into the server-side logs to understand more. I think you're correct that the issue is related to the boolean type, because a similar query using string is successful.

jpaulgale commented 3 days ago

Yes, ultimately my solution was to just use β€œtrue” and β€œfalse” strings, which aside from the time I spent trying to get the Boolean query to work, works just as well for my purposes

On Mon, Nov 25, 2024 at 4:57β€―PM Michael Brooks @.***> wrote:

Thanks for tagging me @WilliamBergamin https://github.com/WilliamBergamin πŸ™‡πŸ» and big props to @jpaulgale https://github.com/jpaulgale for the code samples πŸ‘ŒπŸ»

I was also able to reproduce the issue. πŸŽ‰

I think this a Slack API issue with /api/apps.datastore.query https://api.slack.com/methods/apps.datastore.query.

Slack CLI:

Using the --verbose flag, it looks like the CLI is parsing the query correctly based on the API Request Body and the API Response is an InternalServerError:

$ slack datastore query '{ "datastore": "kudos_data", "expression": "#shared = :false_value", "expression_attributes": {"#shared": "shared_on_channel"}, "expression_values": {":false_value": false} }' --verbose

[2024-11-25 13:31:44] HTTP Request: POST https://slack.com/api/apps.datastore.query HTTP/1.1# HTTP Request Body:# {"datastore":"kudos_data","app_id":"A082EED55SP","expression":"#shared = :false_value","expression_attributes": # {"#shared":"shared_on_channel"},"expression_values":{":false_value":false}}

[2024-11-25 13:31:45] HTTP Response Status: HTTP/1.1 200 OK# HTTP Response Body:# {"ok":false,"error":"datastore_error","errors":[{"code":"datastore_query_error","message":"InternalServerError: An # InternalServerError occurred","pointer":"\/datastore\/kudos_data"}]}

Slack Deno SDK:

I tried Datastore Query using SDK https://api.slack.com/automation/datastores-retrieve#query by adding it to a Workflow Function and I receive a similar API Error when I view the activity logs:

const result = await client.apps.datastore.query({
  "datastore": "kudos_data",
  "expression": "#shared = :false_value",
  "expression_attributes": { "#shared": "shared_on_channel" },
  "expression_values": { ":false_value": false },
});

console.log("Datastore Query Result:");
console.log(result);

$ slack activity -t

2024-11-25 13:46:13 [error] [Datastore:kudos_data] (Trace=Tr082EGB0KSP) Datastore query failed with # '{"expression":"#shared = :false_value","expression_attributes":{"#shared":"shared_on_channel"},"expression_values":# {":false_value":false},"limit":100,"cursor":""}'# # InternalServerError: An InternalServerError occurred# # Datastore Query Result:# {# toFetchResponse: [Function: toFetchResponse],# ok: false,# error: "datastore_error",# errors: [# {# code: "datastore_query_error",# message: "InternalServerError: An InternalServerError occurred",# pointer: "/datastore/kudos_data"# }# ]# }

@WilliamBergamin https://github.com/WilliamBergamin I think we'll have to look into the server-side logs to understand more. I think you're correct that the issue is related to the boolean type, because a similar query using string is successful.

β€” Reply to this email directly, view it on GitHub https://github.com/slackapi/deno-slack-sdk/issues/385#issuecomment-2499119360, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLRK2ICY26NMHW652SBTF32COMOBAVCNFSM6AAAAABSKQO2R2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOJZGEYTSMZWGA . You are receiving this because you were mentioned.Message ID: @.***>

mwbrooks commented 3 days ago

Yes, ultimately my solution was to just use β€œtrue” and β€œfalse” strings

I noticed that as well πŸ€” So, did the following command work when you treat "false" as a string?

$ slack datastore query '{ "datastore": "kudos_data", "expression": "#shared = :false_value", "expression_attributes": {"#shared": "shared_on_channel"}, "expression_values": {":false_value": "false"} }'
jpaulgale commented 3 days ago

Yes, works just fine