TransactWrite update() documentation is wrong
The documentation of TransactWrite's update() method is incorrect. It states that it is expecting model classes as arguments:
The Update operation functions similarly to Model.update.
model_cls (required) hash_key (required) Documentation
The update() method is actually implemented differently, it expects a model instance:
def update(self, model, actions, condition=None, return_values=None):
Source File
cc @hallie
i guess i should take "great attention to detail" off of my resume
@hallie Your commit is still wrong. There is also no hash_key attribute.
I would like to suggest that you change the implementation to reflect the current documentation. It appears to be more logical: The update command can also be used to create a new item if there is currently no item. E.g.:
with TransactWrite(connection=Connection()) as tx:
tx.update(
BankAccount(hash_key='123'),
actions=[BankAccount.balance.set((BankAccount.balance|0).add(10))]
)
It's strange that you have to create a Model-Instance for an item that probably doesn't exist yet. The documented api is more logical IMHO:
with TransactWrite(connection=Connection()) as tx:
tx.update(
BankAccount,
'123',
actions=[BankAccount.balance.set((BankAccount.balance|0).add(10))]
)
@Flips01 I agree that its more logical, but I went with using the model object because that's how Model.update works (its a method on the object, rather than the class)
I would like to suggest that you change the implementation to reflect the current documentation.
I'd also want to add that'd be a breaking change, so updating the current version's documentation should probably happen regardless of the changes we want for the next version.