PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

TransactWrite update() documentation is wrong

Open Flips01 opened this issue 7 years ago • 5 comments

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

Flips01 avatar Oct 31 '19 10:10 Flips01

cc @hallie

ikonst avatar Oct 31 '19 15:10 ikonst

i guess i should take "great attention to detail" off of my resume

hallie avatar Oct 31 '19 17:10 hallie

@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 avatar Oct 31 '19 17:10 Flips01

@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)

hallie avatar Oct 31 '19 17:10 hallie

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.

ikonst avatar Oct 31 '19 19:10 ikonst