dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Problem updating secondary index key

Open jrodz-ak opened this issue 2 years ago • 3 comments

HI there! I'm having problems updating the status of a key on a secondary index, when updating the related attribute.

I've the following entity definition: gsi2pk: { type: 'string', prefix: 'STATUS#', default: (f) => f.status, onUpdate: true }, status: { type: 'string' },

When I create the entry, the status value is 2, and gsi2pk is STATUS#2 BUT when I update the entry, the new status value is 0, and gsi2pk is still STATUS#2

What I understand on the documentation is that I've to define onUpdate to true to update the default value, but it makes no difference.

Is this a bug or I'm missing something?

jrodz-ak avatar Sep 22 '21 14:09 jrodz-ak

I have this problem as well. Any ideas?

ianpogi5 avatar Nov 19 '21 06:11 ianpogi5

@ianpogi5 I bypass the situation updating both values:

userData.status = UserStatus.Deleted;
userData.gsi2pk = UserStatus.Deleted;

but I'll like to know the reason of "onUpdate", and validate if that's an issue or not

jrodz-ak avatar Nov 19 '21 10:11 jrodz-ak

I know it's an old issue, but did you try settings the onUpdate attribute when defining gsi2pk ? I had the same problem and it solved it.

jfreyheit avatar Jan 19 '22 13:01 jfreyheit

Hey @jrodz-ak, thanks for opening this issue and sorry for the delayed response.

@jfreyheit's suggestion is correct, that should fix it for you.

I'll be closing this issue, but feel free to ping me if you need anything 😎 🙏

naorpeled avatar Nov 26 '22 02:11 naorpeled