我有一些我无法删除的dynamoDB记录,我注意到那些有问题的记录都包含特殊字符。我写了一小段测试代码,并且能够重复这个问题:
require 'aws-sdk-core'
require 'aws-record'
class Task
include Aws::Record
set_table_name "blah"
string_attr :customer_id, hash_key: true
string_attr :item, range_key: true
string_attr :operation, default_value: '+'
string_attr :device, default_value: 'office-pc'
string_attr :time, default_value: "00" + Time.now.to_i.to_s
string_attr :quantity, default_value: '1'
end
Aws.config.update(
{
region: 'us-west-2',
credentials: Aws::Credentials.new(
'foo',
'bar'
),
ssl_verify_peer: false
}
)
#insert two rows
task1 = Task.new(customer_id: "a", item: "\u2713")
task1.save()
task2 = Task.new(customer_id: "a", item: "check")
task2.save()
#query and delete both
resp = Task.query({
key_conditions: {
"customer_id" => {
attribute_value_list: ["a"],
comparison_operator: "EQ",
}
}
})
resp.each do
|task|
puts task.item
task.delete!
end
#query again, to see what's left
resp = Task.query({
key_conditions: {
"customer_id" => {
attribute_value_list: ["a"],
comparison_operator: "EQ",
}
}
})
resp.each do
|task|
puts task.item
end
下面是输出,正如您所看到的,前两行显示插入的内容,最后一行显示\ u2713即使在删除后仍然存在。
check
Ô£ô
Ô£ô
gem版本:aws-sdk-core:2.6.49,aws-sdk-resources:2.6.49,aws-record:1.0.3。所有这些都是最新版本。窗户上的红宝石是2.3.1。
答案 0 :(得分:0)
问题在于sdk gem:aws-sdk-core-2.7.0(2.6.5是OP发布时的最新版本,2.7.0是最新版本)。它可以通过lib \ aws-sdk-core \ json \ handler.rb中的单行更改轻松修复。
以下是更改:
def parse_body(context)
if simple_json?(context)
Json.load(context.http_response.body_contents)
else
rules = context.operation.output
json = context.http_response.body_contents.bytes.pack('c*').force_encoding('utf-8')
#below line is the original code
#json = context.http_response.body_contents
Parser.new(rules).parse(json == '' ? '{}' : json)
end
end