Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jpaulgale opened this issue Nov 23, 2024 · 5 comments
Open

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

jpaulgale opened this issue Nov 23, 2024 · 5 comments
Labels
bug Something isn't working needs info not enough information to reproduce or continue

Comments

@jpaulgale
Copy link

jpaulgale commented Nov 23, 2024

The deno-slack versions

"deno-slack-sdk/": "https://deno.land/x/[email protected]/",
"deno-slack-api/": "https://deno.land/x/[email protected]/"

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
@jpaulgale jpaulgale changed the title [BUG] <title> [BUG] Datastore not allowing me to query by boolean field. Nov 23, 2024
@WilliamBergamin
Copy link
Contributor

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?

@WilliamBergamin WilliamBergamin added bug Something isn't working needs info not enough information to reproduce or continue labels Nov 25, 2024
@mwbrooks
Copy link
Member

mwbrooks commented Nov 25, 2024

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
Copy link
Author

jpaulgale commented Nov 25, 2024 via email

@mwbrooks
Copy link
Member

mwbrooks commented Nov 25, 2024

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
Copy link
Author

Yes, works just fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs info not enough information to reproduce or continue
Projects
None yet
Development

No branches or pull requests

3 participants