dynamodb-toolbox/dynamodb-toolbox

Undefined dependencies for Index keys cause Update / Put failures

Closed this issue · 0 comments

Recent updates to the validation of dependsOn attributes, #678, #734, have caused a lot of noise in my tests.
Some of which were actual issues, so thanks for pointing them out!, however most of it was due to my liberal use of sparse indexes on my Entities.

I have a number of optional attributes that if set, can affect or update the index keys. and updates to these entities don't always need to affect them. (ie, if I'm not updating the status I don't want this GSI updated )

    GSI2SK: {
      sortKey: "GSI2",
      default: ({ status, modified }) => {
        return status ? `${prefix.Link}${status}#${modified}` : undefined;
      },
      dependsOn: ["status", "modified"],
      onUpdate: true,
      hidden: true,
    },

As of 0.9.3 updates to these entities fail with Required field 'GSI2SK' depends on attribute(s), one or more of which can't be resolved (status)

From the docs dependsOn is primarily to :

...ensure dependent attributes' default values are calculated first.

but it appears that the fix #677, has made the dependsOn act like required attributes for index key attributes.

I think that is was an unintended side effect, but happy to discuss if my usage/assumptions need adjustment.