PynamoDB
PynamoDB copied to clipboard
Getting 'Failed to write transaction items' error however table & data exist
Hi,
I'm getting the 'Failed to get transaction items' error however the table & its entries are still available.
This is my Dynamodb Model, class BankStatement(Model): class Meta: table_name = 'BankStatement' region = 'eu-west-2' billing_mode = "PAY_PER_REQUEST"
user_id = UnicodeAttribute(hash_key=True)
account_balance = NumberAttribute(default=0)
is_active = BooleanAttribute()
Dynamodb table screen shot,
This is the sample code taken from the documentation, with TransactWrite(connection=connection, client_request_token='super-unique-key') as transaction: # attempting to transfer funds from user1's account to user2's transfer_amount = 1000 transaction.update( BankStatement(user_id='user1'), actions=[BankStatement.account_balance.add(transfer_amount * -1)], condition=( (BankStatement.account_balance >= transfer_amount) & (BankStatement.is_active == True) ) ) transaction.update( BankStatement(user_id='user2'), actions=[BankStatement.account_balance.add(transfer_amount)], condition=(BankStatement.is_active == True) )
And My error is, An error occurred (ResourceNotFoundException) on request (N3NOKJUKNMR49KIKUA2N56KF8RVV4KQNSO5AEMVJF66Q9ASUAAJG) on table (None) when calling the TransactWriteItems operation: Requested resource not found
I'm not sure what's happening here because the resource is actually exist in the table.(You can see the resource in the table screenshot). I followed the same steps & codes described in pynamodb documentation.
Could someone please help me with this? I can't able to figure out what I'm missing.
@saravanaemis I'm having the same issue. I've tracked it down to...
table_name = operation_kwargs.get(TABLE_NAME)
within Connection.dispatch
. that key is not there, so table_name
ends up being None
Hello!, make sure you set the region on the Connection.
For example:
connection = Connection(region = 'eu-west-1')
object = another_object.get_transact_contract()
# https://pynamodb.readthedocs.io/en/latest/transaction.html
try:
with TransactWrite(connection=connection, client_request_token=another_object.guid) as transaction:
transaction.save(object) #condition=(object.guid.not_exits()))
The issue can be traced back to https://github.com/pynamodb/PynamoDB/blob/5.1.0/pynamodb/connection/base.py#L255-L258
In my opinion, region should either be mandatory, or should be cross-checked when a transaction table has a different region set than the region in the connection and raise an exception if they mismatch.
Aditionally, comments on the documentation should be made, because currently I've seen that the default examples don't provide a region on the connection...
By default the region is us-east-1
so that might explain why not everybody encounters this issue.
Hello!, make sure you set the region on the Connection.
For example:
connection = Connection(region = 'eu-west-1') object = another_object.get_transact_contract() # https://pynamodb.readthedocs.io/en/latest/transaction.html try: with TransactWrite(connection=connection, client_request_token=another_object.guid) as transaction: transaction.save(object) #condition=(object.guid.not_exits()))
Where aws credentials (aws_access_key_id and aws_secret_access_key ) should be set for the same, since we have only given host and region details in connection which causes no credential to locate
issue.
With #1003, of PynamoDB 6.x we should no longer default to us-east-1
.
As for the actual issue, I've created #1077.
Duplicate of #1077.