2017-01-20 11 views
0

私は削除できなかったdynamoDBレコードをいくつか持っています。これらのレコードにはすべて特殊文字が含まれています。私は、テストコードの小片を書いて、問題を繰り返すことができました:は、特殊文字を含む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 

は、あなたが見ることができるように、最初の2行が挿入されてしまったかを示す、出力され、最後の行は、\のu2713があることを示しています削除後もまだそこにあります。

check 
Ô£ô 
Ô£ô 

宝石のバージョン:AWS-SDK-コア:2.6.49、AWS-SDK-資源:2.6.49、AWSレコード:1.0.3。それらのすべてが最新バージョンです。 Windowsではrubyは2.3.1です。

+0

来ている何の応答? –

+0

コンソールから削除を確認できますか? –

+0

はい、私はちょうどあなたがコンソールから削除することができる場合、それはコードやsdkで何かが間違っているかもしれないので、言っていた –

答えて

0

この問題は、sdk gem:aws-sdk-core-2.7.0(OPがポストされたときに2.6.49が最新で、2.7.0が最新です)にあります。 lib \ aws-sdk-core \ json \ handler.rbの1行の変更で簡単に修正できます。以下は

変更です:

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 
関連する問題