PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

Update documentation with more/better examples of using the update functions.

Open Valkryst opened this issue 7 years ago • 4 comments

I've been Googling around and checking over the docs for a while now, but there's not enough information to figure out how to update a record in Dynamo using Pynamo.

The following are my best attempts at getting an update to work:


  • Retrieved a record from Dynamo using a get operation on my model.
  • Printed out the record's data for Locked, let's say it's currently set to True.
  • Ran record.update_item("Locked", "False", action="PUT").
  • Printed out the record's data for Locked again. I'd assume that it's going to print False, but it's still set to True.
  • Ran record.save(). I'd assume that this will run the update operation on the record in Dynamo, but the record in Dynamo is also unchanged.
  • I also recieve UserWarning: Legacy attribute updates are depreciated in favor of update actions.

Due to the warning at the end, I tried the next approach.


  • Retrieved a record from Dynamo using a get operation on my model.
  • Printed out the record's data for Locked, let's say it's currently set to True.
  • Ran record.update({"Locked": {"value": "False", "action": "PUT"}}).
  • Printed out the record's data for Locked again. I'd assume that it's going to print False, but it's still set to True.
  • Ran record.save(). I'd assume that this will run the update operation on the record in Dynamo, but the record in Dynamo is also unchanged.

There was no error this time, but nothing updated.


  • Retrieved a record from Dynamo using a get operation on my model.
  • Printed out the record's data for Locked, let's say it's currently set to True.
  • Ran record.Locked = "False".
  • Printed out the record's data for Locked again. It printed False.
  • Ran record.save(). I'd assume that this will run the update operation on the record in Dynamo, but the record in Dynamo is also unchanged.

There was no error this time, the record object updated, but the record in Dynamo did not update.

Valkryst avatar Nov 21 '17 15:11 Valkryst

So it's 2yrs and 3 months and no reply for you. I thought this project looked good but I'm having issues with update too and no serious doubts about using it. Any news/suggestions?

instil-richard avatar Apr 04 '20 00:04 instil-richard

@dotorg-richard it's basically something like:

my_model = MyModel.get('my_hash_key')
my_model.update(
    actions=[
        MyModel.my_field.set(42),
    ],
)

Let us know how we can improve the docs, preferably through a pull request.

ikonst avatar Apr 04 '20 04:04 ikonst

@ikonst what if i use low level API? i can only do get actions but cant update or put properly. I dont have a model but want to apply raw update to some item. Im struggling like the post owner and still cant find an answer.

ofekfeller-glossai avatar May 02 '22 11:05 ofekfeller-glossai

@ofekfeller1 You can always use the boto3 API regardless of this library.

ikonst avatar May 02 '22 14:05 ikonst