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

Error when sending EntityV2 GetItemCommand with property of type binary() #736

Open
clauzond opened this issue May 3, 2024 · 2 comments
Assignees
Labels

Comments

@clauzond
Copy link

clauzond commented May 3, 2024

  • Node version v.16.19.1
  • Package version 1.0.0-alpha.20240129
  • Package @aws-sdk/client-dynamodb version ^3.515.0

The binary property validator does not accept correct values returned by the GetItemCommand. It seems that AWS sends an object which is not always a buffer, such as Uint8Array, instead of returning Buffer.from(uint8Array). The binary property validator throws an error because Buffer.isBuffer(new Uint8Array()) == false).

Example:

export const myEntity = new EntityV2({
    name: 'MyEntityName',
    table: MyTable,
    schema: schema({
        PK: string(),
        SK: string(),
        MyEntityProperty: binary(),
    }),
});

const PK = "MyPartitionKey";
const SK = "MySortKey";
const buffer = deflateSync(JSON.stringify({"key": "value"}));

// PutItemCommand succeeds
await myEntity
        .build(PutItemCommand)
        .item({ PK, SK, MyEntityProperty: buffer })
        .send();

// GetItemCommand fails, error detailed below is thrown
await myEntity
        .build(GetItemCommand)
        .key({ PK, SK })
        .send();

An error is thrown when using GetItemCommand (I do not have the exact stack trace)

[Error]: Invalid attribute in saved item: MyEntityProperty. Should be a binary. Partition key: MyPartitionKey / Sort key: MySortKey
code: 'operations.formatSavedItem.invalidSavedAttribute',
path: 'MyEntityProperty',
payload: {
received: Uint8Array(11282) [
  00, 256, 237, 257, 207, 221, 228, 286, 282, 276, 255,  74,
    6,  15,  71,  67,  37, 227, 242, 265, 223, 256,  64, 254,
  280,  33, 200,   4, 220, 227, 03,  51,  58, 220, 224, 264,
  06,  75,  32, 211,  64, 247, 234, 238, 232, 07,  63, 246,
    47,  16,  11, 246,  76,  81,  50, 236, 216, 207, 275, 277,
    23, 245, 201,  81,  55,  75, 243, 201, 256, 254, 243,  87,
  272, 203,  25, 218, 205, 224, 243, 230, 268, 245, 238,  87,
  235,  72,  26, 205, 214, 233, 228,  18, 223, 255, 241,  31,
  280, 240, 224, 255,
  ... 11182 more items
],
expected: 'binary',
partitionKey: 'MyPartitionKey',
sortKey: 'MySortKey'
@naorpeled
Copy link
Collaborator

@ThomasAribart FYI

@ThomasAribart ThomasAribart self-assigned this May 15, 2024
@ThomasAribart
Copy link
Collaborator

Hi @clauzond and thanks for the issue! Will look into it asap!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants