{"action":"created","issue":{"url":"https://api.github.com/repos/drecom/activerecord-turntable/issues/24","labels_url":"https://api.github.com/repos/drecom/activerecord-turntable/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/drecom/activerecord-turntable/issues/24/comments","events_url":"https://api.github.com/repos/drecom/activerecord-turntable/issues/24/events","html_url":"https://github.com/drecom/activerecord-turntable/pull/24","id":60193517,"number":24,"title":"Handle string shard key","user":{"login":"if1live","id":971476,"avatar_url":"https://avatars.githubusercontent.com/u/971476?v=3","gravatar_id":"","url":"https://api.github.com/users/if1live","html_url":"https://github.com/if1live","followers_url":"https://api.github.com/users/if1live/followers","following_url":"https://api.github.com/users/if1live/following{/other_user}","gists_url":"https://api.github.com/users/if1live/gists{/gist_id}","starred_url":"https://api.github.com/users/if1live/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/if1live/subscriptions","organizations_url":"https://api.github.com/users/if1live/orgs","repos_url":"https://api.github.com/users/if1live/repos","events_url":"https://api.github.com/users/if1live/events{/privacy}","received_events_url":"https://api.github.com/users/if1live/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-07T06:24:30Z","updated_at":"2015-03-29T06:07:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/drecom/activerecord-turntable/pulls/24","html_url":"https://github.com/drecom/activerecord-turntable/pull/24","diff_url":"https://github.com/drecom/activerecord-turntable/pull/24.diff","patch_url":"https://github.com/drecom/activerecord-turntable/pull/24.patch"},"body":"Usually, shard key is integer. but sometimes, shard key can be string.\r\nI can't understand what happen inside library, but it happen. (shard_key=1234 is changed to shard_key=\"1234\")\r\nMaybe this code is cause. https://github.com/drecom/activerecord-turntable/blob/v2.1.1/lib/active_record/turntable/mixer.rb#L189\r\nI modify code to handle shard_key=\"1234\".\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/drecom/activerecord-turntable/issues/comments/87361514","html_url":"https://github.com/drecom/activerecord-turntable/pull/24#issuecomment-87361514","issue_url":"https://api.github.com/repos/drecom/activerecord-turntable/issues/24","id":87361514,"user":{"login":"if1live","id":971476,"avatar_url":"https://avatars.githubusercontent.com/u/971476?v=3","gravatar_id":"","url":"https://api.github.com/users/if1live","html_url":"https://github.com/if1live","followers_url":"https://api.github.com/users/if1live/followers","following_url":"https://api.github.com/users/if1live/following{/other_user}","gists_url":"https://api.github.com/users/if1live/gists{/gist_id}","starred_url":"https://api.github.com/users/if1live/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/if1live/subscriptions","organizations_url":"https://api.github.com/users/if1live/orgs","repos_url":"https://api.github.com/users/if1live/repos","events_url":"https://api.github.com/users/if1live/events{/privacy}","received_events_url":"https://api.github.com/users/if1live/received_events","type":"User","site_admin":false},"created_at":"2015-03-29T06:07:34Z","updated_at":"2015-03-29T06:07:34Z","body":"Sorry. I can't make reproducible example. I didn't understand current project. I provide call stack.\r\n\r\n## Code\r\nI edit two code for logging.\r\n\r\n### active_record/turntable/cluster.rb\r\n```ruby\r\ndef shard_for(key)\r\n  if key.is_a? String\r\n    p key\r\n    puts caller\r\n    exit\r\n  end\r\n    @shards[@algorithm.calculate(key)]\r\n  rescue\r\n    raise ActiveRecord::Turntable::CannotSpecifyShardError,\r\n      \"cannot select_shard for key:#{key}\"\r\nend\r\n```\r\n\r\n### active_record/turntable/mixer.rb : line 189\r\n```ruby\r\ndef build_update_fader(tree, method, query, *args, &block)\r\n  shard_keys = find_shard_keys(tree.where, @proxy.klass.table_name, @proxy.klass.turntable_shard_key.to_s); puts \"shard_keys : #{shard_keys}\"\r\n  shards_with_query = if shard_keys.present?\r\n  ...\r\n```\r\n\r\n### Log\r\ndebug print message and call stack. I use current master branch.\r\n\r\n```\r\nshard_keys : [1321]\r\nshard_keys : [1321]\r\nshard_keys : [\"1321\"]\r\n\"1321\"\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/mixer.rb:191:in `block in build_update_fader'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/mixer.rb:191:in `map'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/mixer.rb:191:in `build_update_fader'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/mixer.rb:41:in `build_fader'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/connection_proxy.rb:61:in `method_missing'\r\n(eval):30:in `update_record'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/attribute_methods/dirty.rb:74:in `update_record'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:310:in `block in update_record'\r\n__proj__/vendor/ruby/2.1.0/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:373:in `_run__4067321378248301272__update__callbacks'\r\n__proj__/vendor/ruby/2.1.0/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:310:in `update_record'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/timestamp.rb:70:in `update_record'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/persistence.rb:477:in `create_or_update'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:302:in `block in create_or_update'\r\n__proj__/vendor/ruby/2.1.0/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:403:in `_run__4067321378248301272__save__callbacks'\r\n__proj__/vendor/ruby/2.1.0/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:302:in `create_or_update'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/persistence.rb:128:in `save!'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/validations.rb:57:in `save!'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/attribute_methods/dirty.rb:41:in `save!'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/transactions.rb:275:in `block in save!'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/active_record_ext/transactions.rb:15:in `block in with_transaction_returning_status'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/cluster.rb:70:in `call'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/cluster.rb:70:in `block in shards_transaction'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/cluster.rb:69:in `shards_transaction'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/connection_proxy.rb:22:in `shards_transaction'\r\n__proj__/vendor/ruby/2.1.0/bundler/gems/activerecord-turntable-60ce80c1a12a/lib/active_record/turntable/active_record_ext/transactions.rb:12:in `with_transaction_returning_status'\r\n__proj__/vendor/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/transactions.rb:275:in `save!'\r\n__proj__/spec/controllers/quest_continues_controller_spec.rb:58:in `block (4 levels) in <top (required)>'\r\n__proj__/vendor/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `instance_eval'\r\n__proj__/vendor/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `block in run'\r\n__proj__/vendor/ruby/2.1.0/gems/rspec-rails-2.14.0/lib/rspec/rails/example/controller_example_group.rb:158:in `call'\r\n__proj__/vendor/ruby/2.1.0/gems/rspec-rails-2.14.0/lib/rspec/rails/example/controller_example_group.rb:158:in `block (2 levels) in <module:ControllerExampleGroup>'\r\n...rspec-rails...\r\n```"}}