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] Range key needs to be provided to Model.get even when Range key is a constant #1623

Open
6 tasks done
GTRanger opened this issue Aug 1, 2023 · 0 comments
Open
6 tasks done

Comments

@GTRanger
Copy link

GTRanger commented Aug 1, 2023

Summary:

The range key needs to be provided when calling Model.get even in circumstances where it is deterministic. This behavior is inconsistent with Model.create. I suspect this also applies to the hash key as well but I haven't tried it.

Code sample:

Schema

const schema = new dynamoose.Schema({
  PK: {
    type: String,
    hashKey: true,
    alias: "id",
  },
  SK: {
    type: dynamoose.type.CONSTANT("metadata"),
    default: "metadata",
    forceDefault: true,
    rangeKey: true,
  },
})

Model

const MyModel = dynamoose.model("MyModel", schema)

General

await MyModel.create({"id": "1"})
await MyModel.get({id: "1"})

Current output and behavior (including stack trace):

ValidationException: The number of conditions on the keys is invalid
at throwDefaultError (node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8:22)
      at deserializeAws_json1_0GetItemCommandError (node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:1740:51)
      at node_modules/@aws-sdk/client-dynamodb/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
      at node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:14:20
      at node_modules/@aws-sdk/client-dynamodb/node_modules/@aws-sdk/middleware-retry/dist-cjs/retryMiddleware.js:27:46
      at node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:5:22
      at main (node_modules/dynamoose/dist/aws/ddb/internal.js:6:20)
      at node_modules/dynamoose/dist/Model/index.js:771:34

Expected output and behavior:

MyModel.get should return the persisted object without requiring that the SK field is passed in

Environment:

Operating System: MacOS
Operating System Version: 13.4
Node.js version (node -v): 18.x
NPM version: (npm -v): 9.5.1
Dynamoose version: 3.x

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant