diff --git a/moto/dynamodb2/responses.py b/moto/dynamodb2/responses.py index b9689c570..3e0b36aab 100644 --- a/moto/dynamodb2/responses.py +++ b/moto/dynamodb2/responses.py @@ -947,7 +947,13 @@ class DynamoHandler(BaseResponse): "Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributeUpdates} Expression parameters: {UpdateExpression}", ) # We need to copy the item in order to avoid it being modified by the update_item operation - existing_item = copy.deepcopy(self.dynamodb_backend.get_item(name, key)) + try: + existing_item = copy.deepcopy(self.dynamodb_backend.get_item(name, key)) + except ValueError: + return self.error( + "com.amazonaws.dynamodb.v20111205#ResourceNotFoundException", + "Requested resource not found", + ) if existing_item: existing_attributes = existing_item.to_json()["Attributes"] else: diff --git a/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py b/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py index be73b9b07..8c8faea22 100644 --- a/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py +++ b/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py @@ -534,3 +534,18 @@ def test_transact_write_items__too_many_transactions(): err = exc.value.response["Error"] err["Code"].should.equal("ValidationException") err["Message"].should.match("Member must have length less than or equal to 25") + + +@mock_dynamodb2 +def test_update_item_non_existent_table(): + client = boto3.client("dynamodb", region_name="us-west-2") + with pytest.raises(client.exceptions.ResourceNotFoundException) as exc: + client.update_item( + TableName="non-existent", + Key={"forum_name": {"S": "LOLCat Forum"}}, + UpdateExpression="set Body=:Body", + ExpressionAttributeValues={":Body": {"S": ""}}, + ) + err = exc.value.response["Error"] + assert err["Code"].should.equal("ResourceNotFoundException") + assert err["Message"].should.equal("Requested resource not found")