Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11615 (new defect)

Opened 3 weeks ago

Last modified 2 weeks ago

datetime_select raises ActiveRecord::MultiparameterAssignmentErrors with years > 2038

Reported by: moorage Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 2.0.1
Severity: normal Keywords: datetime 2038
Cc:

Description

I'm getting MultiparameterAssignmentErrors (on Mac OS X) when I submit a form using datetime_select and select any year greater than 2038. I've been trying to find solutions for this across the web, but it looks like it's a different bug than those that have been reported/fixed in the past.


ActiveRecord::MultiparameterAssignmentErrors in EmailsController#create

1 error(s) on assignment of multiparameter attributes

/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2397:in `execute_callstack_for_multiparameter_attributes' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2377:in `assign_multiparameter_attributes' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2120:in `attributes=' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1926:in `initialize' app/models/email.rb:27:in `initialize' app/controllers/emails_controller.rb:32:in `new'


{"authenticity_token"=>"a98ad2af6ff97bee4385f222f90f04071aed7b75",

"save_or_draft"=>"Send Email", "email"=>{"send_at(4i)"=>"10", "send_at(5i)"=>"39", "body"=>"", "timezone"=>"America/Los_Angeles", "subject"=>"", "send_at(1i)"=>"2039", "send_at(2i)"=>"4", "send_at(3i)"=>"26"}}


create_table :emails do |t|

t.integer :user_id t.boolean :sent, :sending_in_progress, :draft, :error, :default => false t.string :bcc, :subject, :preview, :timezone, :error_message t.text :body t.datetime :send_at

t.timestamps

end


<%= f.datetime_select :send_at, :order => [:month,:day, :year], :start_year => Time.now.year, :end_year => Time.now.year + 100, :default => Time.now %>

Attachments

TimeTest.zip (96.5 kB) - added by moorage on 04/29/08 01:00:23.
An example project using only this feature.

Change History

04/26/08 18:24:55 changed by moorage

Here is the actual error:

MultiparameterAssignmentErrors:

message: ActiveRecord::AttributeAssignmentError exception: #<ArgumentError: time out of range> attribute: "send_at"

04/27/08 17:37:04 changed by dibistore

No problems here with edge rails. I'm using sqlite3. Can you test it in a fresh app where you use only that feature?

04/28/08 09:25:11 changed by fcheung

I don't think this is a rails issue, just a ruby issue: when ruby's Time is represented by a 32 bit integer, the point at which it rolls over (ie the greatest date representable) is some time in 2038. You may be able to convince rails to use an instance of DateTime rather than Time (which has a much much greater range)

04/29/08 01:00:23 changed by moorage

  • attachment TimeTest.zip added.

An example project using only this feature.

04/29/08 01:06:20 changed by moorage

I created an example project (TimeTest, attached) using only this feature, with sqlite3. I indeed still get the same error for dates with year >= 2038: ActiveRecord::MultiparameterAssignmentErrors (1 error(s) on assignment of multiparameter attributes)

In addition, if I set :default => { :year => 2038 } to any year > 2037, I get "time out of range". <%= f.datetime_select :send_at, :order => [:month,:day, :year], :start_year => Time.now.year, :end_year => Time.now.year + 100, :default => {:year => 2038} %>

Is there a patch for Ruby that I don't have, or something - that fixes dates > 2038? Thanks!

Here's my versions of ruby and rails:


Macintosh-3:TimeTest$ ruby --version
ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0]

Macintosh-3:TimeTest$ rails --version
Rails 2.0.2

05/05/08 15:01:46 changed by daviscabral

I have this problem too, but the field have years that are minor than 2038.

My date field is: <%= f.date_select :dob, :order => [:day, :month, :year], :start_year => 1900, :end_year => 18.years.ago.strftime('%Y').to_i %>

My Rails is 2.0.2 and Ruby 1.8.6.

My error only occurs when the year selected is minor than 1970.