views:

79

answers:

1

Using Rails 2.3.2 (not in a good situation to upgrade at the moment) with ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]. Getting the following error when trying to save when doing validations on the model, if the validations are :on => :update. If I change the validations to :on => :create and create a new record, I don't see the error, and I have no problem saving it if there are no validations.

Completed in 392ms (View: 10, DB: 296) | 200 OK [http://localhost/barfoos/update]
/!\ FAILSAFE /!\  Tue Sep 14 16:38:49 -0400 2010
  Status: 500 Internal Server Error
  User can't be referred
    /path/to/project/vendor/rails/activerecord/lib/active_record/session_store.rb:67:in `dump'
    /path/to/project/vendor/rails/activerecord/lib/active_record/session_store.rb:67:in `marshal'
    /path/to/project/vendor/rails/activerecord/lib/active_record/session_store.rb:123:in `marshal_data!'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `send'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `evaluate_method'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in `call'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
    /path/to/project/vendor/rails/activesupport/lib/active_support/callbacks.rb:276:in `run_callbacks'
    /path/to/project/vendor/rails/activerecord/lib/active_record/callbacks.rb:344:in `callback'
    /path/to/project/vendor/rails/activerecord/lib/active_record/callbacks.rb:249:in `create_or_update'
    /path/to/project/vendor/rails/activerecord/lib/active_record/base.rb:2539:in `save_without_validation'
    /path/to/project/vendor/rails/activerecord/lib/active_record/validations.rb:1009:in `save_without_dirty'
    /path/to/project/vendor/rails/activerecord/lib/active_record/dirty.rb:79:in `save_without_transactions'
    /path/to/project/vendor/rails/activerecord/lib/active_record/transactions.rb:229:in `send'
    /path/to/project/vendor/rails/activerecord/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
    /path/to/project/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
    /path/to/project/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in `transaction'
    /path/to/project/vendor/rails/activerecord/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
    /path/to/project/vendor/rails/activerecord/lib/active_record/transactions.rb:196:in `save_without_unsaved_flag'
    /path/to/project/vendor/rails/activerecord/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
    /path/to/project/vendor/rails/activerecord/lib/active_record/transactions.rb:196:in `save_without_unsaved_flag'
    /path/to/project/vendor/plugins/active_scaffold/lib/extensions/unsaved_record.rb:15:in `save'
    /path/to/project/vendor/rails/activerecord/lib/active_record/session_store.rb:300:in `set_session'
    /path/to/project/vendor/rails/activerecord/lib/active_record/base.rb:1453:in `silence'
    /path/to/project/vendor/rails/activerecord/lib/active_record/session_store.rb:297:in `set_session'
    /path/to/project/vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb:132:in `call'
    /path/to/project/vendor/rails/activerecord/lib/active_record/query_cache.rb:29:in `call'
    /path/to/project/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
    /path/to/project/vendor/rails/activerecord/lib/active_record/query_cache.rb:9:in `cache'
    /path/to/project/vendor/rails/activerecord/lib/active_record/query_cache.rb:28:in `call'
    /path/to/project/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
    /path/to/project/vendor/rails/actionpack/lib/action_controller/reloader.rb:9:in `call'
    /path/to/project/vendor/rails/actionpack/lib/action_controller/failsafe.rb:11:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /path/to/project/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:106:in `call'
    /path/to/project/vendor/rails/railties/lib/rails/rack/static.rb:31:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
    /path/to/project/vendor/rails/railties/lib/rails/rack/log_tailer.rb:17:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:50:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:14:in `run'
    /path/to/project/vendor/rails/railties/lib/commands/server.rb:111
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3

The model looks like this:

class Barfoo < ActiveRecord::Base
  default_scope :conditions => {:scoping_model_id => ScopingModel.current_version.id}
  belongs_to :scoping_model

  # validate is false to keep from attempting to validate Foobar on Barfoo save, as Foobar can be saved, even if invalid, unlike Barfoo.
  has_one :foobar, :validate => false
  validates_presence_of :foobar_id, :on => :create, :message => "can't be blank"
  validates_inclusion_of :accepted_an_agreement, :in => [true, false], :on => :update, :message => "please choose whether you agree or disagree"
  validates_presence_of :some_option_string, :on => :update, :message => "before agreeing, you must specify the some string", :if => Proc.new { |detail| detail.accepted_an_agreement == true }
  validates_presence_of :some_text, :on => :update, :message => "you must provide details if option is 'Other'", :if => Proc.new { |detail| detail.some_option_string == 'Other' }
end

What I specify as the values of these fields doesn't matter, and as Shadwell notes in his comment below, it appears to be session-related. There is one thing session-related and user-related that we do in ApplicationController that could be causing this issue, even though it's never been a problem before now. ApplicationController looks like:

class ApplicationController < ActionController::Base
  include ExceptionNotifiable
  require 'something_that_defines_update_method_that_we_redefine_in_controller'
  include Userstamp

  ActionController::Base.session_options[:httponly] = true
  ActionController::Base.session_options[:secure] = true

  prepend_before_filter :user_setting_method

  ...

  protected

  def user_setting_method
    session[:username] ||= optional_override_username
    session[:username] = session[:username]  # touch the session for timeout purposes
    @user ||= User.find_by_username session[:username]
    true
  end

  ...

end

Search didn't bring up much about /!\ FAILSAFE /!\ with User can't be referred. Any idea about what would cause this and are there common solutions to this or things to look for that might be wrong?

Note that the foobar instance attached to this is saved, but in this particular case, foobar has previously been saved long before, but does not validate (was saved without validation, which is a normal possible state, since it is data from a multi-page form that saves the data partially and user can come back and correct later to finish).

A: 

After continuing to develop the model a bit more I started getting another error:

/!\ FAILSAFE /!\  Fri Sep 17 14:53:50 -0400 2010
  Status: 500 Internal Server Error
  can't dump hash with default proc

I tried saving the model in console and was successful, but saw some wierd things. It was asking for foobar_id to be valid (for example) when I'd already set a valid foobar on the model. So, I talked about it with a team member and heard that he had read about issues trying to validate on id of an associated object like that.

I removed:

validates_presence_of :foobar_id, :on => :create, :message => "can't be blank"

and it worked.

But, it was suggested to me by another coworker that the issues I was having were probably related to doing validates_presence_of :foobar_id, when, in the controller, I was attempting to set foobar:

barfoo.foobar = foobar

rather than setting foobar_id like:

barfoor.foobar_id = foobar.id

I also noticed that, with the former example, it wasn't setting foobar_id in the related row in the database.

After changing it to set foobar_id on barfoo, it seems to save on create and update as long as there is no update validation. However, if I add validation that validates :on => :update, it fails.

Gary S. Weaver