Open LucasDachman opened 3 years ago
Seems like this is due to line 310 in condition-expression-builder.ts
. The validator throws if the conditional values length is falsey. Why is this needed?
function validateForOperator(operator: ConditionOperator, values?: any[]) {
validateArity(operator, values)
/*
* validate values if operator supports values
*/
if (!isFunctionOperator(operator) || (isFunctionOperator(operator) && !isNoParamFunctionOperator(operator))) {
if (values && Array.isArray(values) && values.length) {
validateValues(operator, values)
} else {
throw new Error(
dynamicTemplate(ERR_ARITY_DEFAULT, { parameterArity: operatorParameterArity(operator), operator }),
)
}
}
}
Also empty arrays are striped by the deepFilter
in buildFilterExpression
in condition-expression-builder.ts
. Is this necessary?
export function buildFilterExpression(
attributePath: string,
operator: ConditionOperator,
values: any[],
existingValueNames: string[] | undefined,
metadata: Metadata<any> | undefined,
): Expression {
// metadata get rid of undefined values
values = deepFilter(values, (value) => value !== undefined)
This is legal to DynamoDB
TransactItems: [
{
Update: {
TableName: ...,
Key: ...,
ConditionExpression: 'myList = :emptyList',
UpdateExpression: 'SET myList = :myList',
ExpressionAttributeValues: {
':emptyList': { L: [] },
':myList': { L: [{ S: 'value' }] },
},
},
}
]
any progress on this issue? I'm experiencing the same problem which leads to an issue with GraphQL resolvers with nonNull lists
I ended up just using the using the dynamodb client directly for this specific use case.
This problem extends to all actions containing empty arrays, not just condition expressions. I can't see any reason deepFilter
doesn't allow empty arrays. They are 100% valid in dynamoDB. Not sure this repo is actively maintained anymore though. Forked repo and fixed here: https://github.com/Fantom-App/dynamo-easy/pull/1
Any changes the suggested fix will be added into this repo? Would be great 😄
Describe the bug
If I have a property with a custom mapper like
and I try to do a conditional transact update like:
I get
Error: expected 1 value(s) for operator =, this is not the right amount of method parameters for this operator
This works fine if the list is populated but fails when the list is empty
Expected behavior I expect the operation to succeed if the list is empty and fail if the list is not empty. I do not expect an error