Why are updates partial by default for nested attributes? #854
Replies: 3 comments 4 replies
-
There's no particular reason. I though partial updates were more frequent than complete overrides but I may have been wrong. I realise that the fact that the syntax is the reverse of the v0 one is confusing though ( Would a await PokemonEntity.build(UpdateItemCommand)
.item({
pokemonId: 'Pikachu',
trainer: 'Ash',
data: $partial({
moves: $set(['Thunderbolt', 'Quick Attack']),
}),
})
.send(); Note that this |
Beta Was this translation helpful? Give feedback.
-
I think it would be a good idea to give us a means to NOT update partially. We have one use case where we update a VERY large object with many nested lists, maps or records. Usually we can get away with calling a serialize function to export a JSON representation and spread that value into an Update Command's For instance, we were able to use something like this: await this.entity.build(UpdateItemCommand).item({
...myData,
pkVal,
id,
})
.send(); Where However, to get around the shortcomings of the partial-by-default issue, we have to use something like the following: await this.entity.build(UpdateItemCommand).item({
...myData,
pkVal,
id,
dat1: $set(myData.dat1),
dat2: $set(myData.dat2),
// ...etc
})
.send(); Allowing us to utilize $set-by-default using a configuration would be nice. |
Beta Was this translation helpful? Give feedback.
-
@methompson @gabrielcolson Check out the docs: https://www.dynamodbtoolbox.com/docs/entities/actions/update-attributes |
Beta Was this translation helpful? Give feedback.
-
We heavily use the
UpdateItem
commands as "upserts" in order to create the object if it does not exist.During our migration from 0.x to 1.x, we introduced a lot of hard to find bugs because of the new default behavior for nested attributes: a partial update of a nested attributes throws a runtime error if the attribute is not already set.
When using the DocumentClient, you have to explicitly update the nested attribute in the update expression if you want to partially update this attribute. I would have expected dynamodb-toolbox to work the same way.
This makes us reconsider wether or not we want to upgrade in the rest of the system because this behavior is very prone to errors.
Beta Was this translation helpful? Give feedback.
All reactions