rails/rails — Issue #3673: Marshaling DateTime attributes from before 1900 doesn't work.
Author: michaeleconomy
Created: 2011-11-18 03:10:56+00:00
State: open

So we are in the process of upgrading from ruby 2.3.11 to 3.1.1

i have a ActiveRecord called Author, Author has a born_at column (mysql - datetime). A few of our authors happen to have been before 1900 (mark twain, etc), and when they get marshalled (to get stored into memcached) it doesn't work!

It appears that the cut off is the year 1900.

>> a = Author.find_by_name "Jane Austen"; nil
Author Load (0.4ms) SELECT `authors`.* FROM `authors` WHERE `authors`.`name` = 'Jane Austen' LIMIT 1
=> nil
>> Marshal.dump a
ArgumentError: year too big to marshal
from (irb):18:in `_dump'
from (irb):18:in `dump'
from (irb):18
from :0
>> Marshal.dump 112.years.ago
ArgumentError: year too big to marshal
from (irb):20:in `_dump'
from (irb):20:in `dump'
from (irb):20
from :0

I'm hacking it with:

class Time

def _dump(arg = nil)
to_datetime._dump(arg)
end

def self._load(string)
DateTime._load(string).to_time
end

end

to get this to work, but clearly thats not optimal.