PynamoDB
PynamoDB copied to clipboard
Update documentation with more/better examples of using the update functions.
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 toTrue
. - 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 printFalse
, but it's still set toTrue
. - 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 toTrue
. - 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 printFalse
, but it's still set toTrue
. - 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 toTrue
. - Ran
record.Locked = "False"
. - Printed out the record's data for
Locked
again. It printedFalse
. - 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.
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?
@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 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.
@ofekfeller1 You can always use the boto3
API regardless of this library.