jasonmk / datastax_rails

A Ruby-on-Rails interface to Datastax Enterprise. Replaces the majority of ActiveRecord functionality.
MIT License
23 stars 9 forks source link

Cassandra 2 - error when trying to write boolean columns #20

Closed trushkevich closed 10 years ago

trushkevich commented 10 years ago

I tryied to write a boolean column, but got the error (see below). I found that DatastaxRails::Types::BooleanType#encode is responsible for converting all boolean values either to "0" or to "1", so I tried to change

TRUE_VALS.include?(bool) ? '1' : '0'

to

TRUE_VALS.include?(bool) ? true : false

but just got "Invalid STRING constant (false)" instead of "Invalid STRING constant (0)". The root seems to be in cassandra-rb. May be some query sanitizing... I just stopped digging and switched from boolean to varchar :)

CassandraCQL::Error::InvalidRequestException: Invalid STRING constant (0) for checked of type boolean from /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/lib/cassandra-cql/database.rb:126:in 'rescue in execute_cql_query' from /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/lib/cassandra-cql/database.rb:115:in 'execute_cql_query' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/cql/base.rb:25:in 'execute' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:124:in 'write_with_cql' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:70:in 'block (2 levels) in write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/notifications.rb:161:in 'instrument' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:66:in 'block in write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:65:in 'tap' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:65:in 'write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:247:in '_write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:234:in '_create' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/callbacks.rb:33:in 'block in _create' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:113:in 'call' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:113:in 'call' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in 'block in halting' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:86:in 'call' ... 13 levels... from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/console.rb:9:in 'start' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:69:in 'console' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in 'run_command!' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands.rb:17:in '[top (required)]' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in 'require' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in 'block in require' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in 'load_dependency' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in 'require'

jasonmk commented 10 years ago

Give it a try now with version 2.0.0 (you'll have to drop and re-create your schema). It's now using cql-rb and Cassandra's native type system so it should work a lot better.