You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the Bug
When a GSI Partition Key is declared as string or null, put transactions fail when the value for the GSI Partition Key is a string. The put transaction does not fail when it's value is null.
This situation occurs when you want to use a sparse index on the GSI. In this case, we declare the GSI Partition Key to be string or null.
Expected behavior
Both transactions should be assembled and be ready to execute with transaction writer. However, the second put transaction fails with the following error. Curiously, the first transaction is assembled without issue.
TypeError: Cannot read property 'properties' of undefined
at Metadata.forProperty (/Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/decorator/metadata/metadata.js:24:31)
at /Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/mapper/mapper.js:64:101
at Array.forEach (<anonymous>)
at Object.toDb (/Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/mapper/mapper.js:49:19)
at Object.objectToDb [as toDb] (/Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/mapper/for-type/object.mapper.js:20:26)
at toDbOne (/Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/mapper/mapper.js:103:18)
at /Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/mapper/mapper.js:72:38
at Array.forEach (<anonymous>)
at Object.toDb (/Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/mapper/mapper.js:49:19)
at new TransactPut (/Users/estewart/Developer/Learning/DynamoDB/DynamoEasyIssue/node_modules/@shiftcoders/dynamo-easy/dist/dynamo/transactwrite/transact-put.js:12:37)
Desktop (please complete the following information):
OS: macOS Catalina 10.15.3
Typescript Version: 3.8.3
Node Version: 13.8.0
Package:
{
"name": "dynamo-easy-issue",
"version": "0.0.1",
"description": "Proof of concept for an issue with GSI Primary keys that allow null",
"main": "src/index.ts",
"author": "Eric Lee Stewart",
"license": "ISC",
"scripts": {
"build": "tsc",
"run": "node dist/app/index.js",
"transpile": "tsc"
},
"dependencies": {
"@shiftcoders/dynamo-easy": "^5.6.0",
"aws-sdk": "^2.637.0",
"reflect-metadata": "^0.1.13",
"tslib": "^1.11.1",
"uuid": "^7.0.2"
},
"devDependencies": {
"@types/node": "^13.9.0",
"@types/uuid": "^7.0.0",
"typescript": "^3.8.3"
}
}
The text was updated successfully, but these errors were encountered:
sans-ericstewart
changed the title
TransactPut fails with GSIPartitionKey is defined as "string | null" and a value is used for this property.
TransactPut fails when GSIPartitionKey is defined as "string | null" and a value is used for this property.
Mar 11, 2020
Basically it is not a bug but somehow an expectable behaviour.
dynamo-easy relies on typescript reflection information design:type to skip type checks on values at runtime. When defining masterAccountId: string | null the emitted design type is Object and not String --> this results in dynamo-easy trying to treat your string value like an object and therefore it fails. The null value on the other hand is ignored and won't be sent to dynamoDB since this is the default behaviour of dynamo-easy.
Unfortunately dynamo-easy does not yet support null values for properties.
My first idea was to handle your case by simply creating a custom mapper, but all null or undefined values are filtered out before the mapper is called. So this won't work as well.
tl;dr
since dynamo-easy can't handle null values, you'll have to use a special string value AND a custom mapper to eventually store {S:'val'} or {NULL:true} to DynamoDB.
If it's ok to not store a value at all instead of null, you should be fine with masterAccountId?: string
Describe the Bug
When a GSI Partition Key is declared as string or null, put transactions fail when the value for the GSI Partition Key is a string. The put transaction does not fail when it's value is null.
This situation occurs when you want to use a sparse index on the GSI. In this case, we declare the GSI Partition Key to be string or null.
Code to Reproduce the Issue
Expected behavior
Both transactions should be assembled and be ready to execute with transaction writer. However, the second put transaction fails with the following error. Curiously, the first transaction is assembled without issue.
Desktop (please complete the following information):
Package:
The text was updated successfully, but these errors were encountered: