Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

problem with is_dirty method #54

Closed
phoet opened this Issue Feb 16, 2012 · 5 comments

Comments

Projects
None yet
2 participants
Contributor

phoet commented Feb 16, 2012

i want to write a migration where i just try to force save documents to the database, so that defaults, that i intruduced at some point get updated in the documents.

when i try to update my user model user.is_dirty; user.save! i get an NoMethodError: undefined method 'email_changed?' for #<User:0x007fb223c1d478> error.

this seems to come from simple_property.rb and looks like a validation-callback from active-model:

  def dirty?(object)
    object.send("#{name}_changed?")
  end

i really did not understand how this should be working. are there some magic helper methods generated somewhere that should provide methods like email_changed? for all my model classes?

on the other hand if i update the e-mail property everything works fine:

1.9.3-p0 :011 > user.email = 'uschi@muschiiiii.de'; user.save!
 => true 

here is the stack:

1.9.3-p0 :009 > u.is_dirty;u.save!
NoMethodError: undefined method `email_changed?' for #<User:0x007fb223c1d478>
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/persistence/ghost_attributes.rb:7:in `method_missing'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/persistence/dirty_attributes.rb:32:in `method_missing'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/attribute_methods.rb:385:in `method_missing'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:446:in `_run_validate_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/validations.rb:212:in `run_validations!'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/validations.rb:179:in `valid?'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:174:in `valid_document?'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:157:in `block (2 levels) in update_document'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_validation_on_update_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:156:in `block in update_document'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_validation_on_save_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:155:in `update_document'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:81:in `save_document'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:88:in `save_document!'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:120:in `block in save!'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:102:in `block in with_database'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato.rb:44:in `with_database'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:101:in `with_database'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:119:in `save!'
    from (irb):9
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from scri = User.last
 => #<User _id: "c1ce28d993958de695f8fe45a0181aed", _rev: "14-dc2d20691289523ab02f7b51be75a6ce", created_at: Wed, 15 Feb 2012 15:41:19 CET +01:00, updated_at: Thu, 16 Feb 2012 10:54:48 CET +01:00, email: "uschi@muschi.de", encrypted_password: "$2a$10$BaM29xYH/JPMuf82orRrVOR1uql/tpKj/4HTpkshTd/6B3NJCmaym", authentication_token: nil, remember_created_at: nil, reset_password_token: nil, reset_password_sent_at: nil, confirmation_token: nil, confirmed_at: Wed, 15 Feb 2012 15:43:00 CET +01:00, confirmation_sent_at: Wed, 15 Feb 2012 15:41:19 CET +01:00, failed_attempts: nil, unlock_token: nil, locked_at: nil, sign_in_count: 1, current_sign_in_at: Wed, 15 Feb 2012 15:43:00 CET +01:00, last_sign_in_at: Wed, 15 Feb 2012 15:43:00 CET +01:00, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", first_name: "uschi", last_name: "müller", disable_mailings: nil, one_click_token: "8FvxZPqakU9F4JQQLEPY", salutation_code: "mr", password: nil, last_terms_of_use_check: Tue, 20 Dec 2011, site_code: "DE"> 
1.9.3-p0 :011 > u.email = 'uschi@muschiiiii.de';u.save!
 => true 
Owner

langalex commented Feb 16, 2012

yes the *_changed? methods are generated by ActiveModel. I don't really have time right now to dig into your problem, sorry. I might have some time tomorrow but can't promise anything.

Owner

langalex commented Feb 26, 2012

are you still getting this with the current master? made some changes in that area in the past days.

@phoet phoet closed this Feb 28, 2012

Contributor

phoet commented Feb 28, 2012

our test-suite passes with couch_potato master at d66fec500ad475bd2e8dc7b9ce059874f0c18017 and the dirty issue does not occur anymore.

Contributor

phoet commented Feb 28, 2012

one thing that we experienced after the update is that after the first call our response-time rises extremely:

Completed 200 OK in 328.3ms (Views: 219.170ms | CouchDB: 40.058ms(5q))
Completed 200 OK in 1166.0ms (Views: 285.441ms | CouchDB: 10.218ms(3q))

Contributor

phoet commented Feb 29, 2012

problem disappears with rails 3.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment