attr-encrypted / attr_encrypted

Generates attr_accessors that encrypt and decrypt attributes
MIT License
2.01k stars 427 forks source link

update_attributes breaks with undefined method 'to_sym' for ...:Fixnum #200

Open tilo opened 8 years ago

tilo commented 8 years ago

I have a Rails 4.2.4 model, which uses attr_encrypted 1.3.4, and it has a user_id.

When deleting a user-account, I need to dis-associate the records for this model from the user account.

  user_id = current_user.id
  MyModel.where(:user_id => user_id).each do |c|
    # c.update_attribute(c.user_id , nil)  # update_attribute BREAKS
    c.update_attributes(c.user_id => nil)  # update_attributes BREAKS also
    # setting user_id=nil and saving it works
  end

the stack-trace for this is not very helpful, because it does not include the source-line in the above code..

NoMethodError: undefined method `to_sym' for 742:Fixnum
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/attr_encrypted-1.3.4/lib/attr_encrypted/adapters/active_record.rb:28:in `block in perform_attribute_assignment'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/attr_encrypted-1.3.4/lib/attr_encrypted/adapters/active_record.rb:28:in `reject'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/attr_encrypted-1.3.4/lib/attr_encrypted/adapters/active_record.rb:28:in `perform_attribute_assignment'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/attr_encrypted-1.3.4/lib/attr_encrypted/adapters/active_record.rb:35:in `assign_attributes_with_attr_encrypted'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/persistence.rb:251:in `block in update'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:220:in `transaction'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/persistence.rb:250:in `update'
    from (irb):5:in `block in irb_binding'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/relation/delegation.rb:46:in `each'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/relation/delegation.rb:46:in `each'
    from (irb):4
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /opt/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
saghaulor commented 8 years ago

@tilo is this an issue with the newest version of attr_encrypted?