
[PATCH]ArgumentError: argument out of range when timestamp column is 0000-00-00 00:00:00
Reported by Guillaume Maury (giom) | June 3rd, 2008 @ 01:00 PM
Short answer
The problem is that whenever I would access a Time attribute it would raise an ArgumentError: argument out of range error.
Longer Answer
I had the following class
class Test
include DataMapper::Resource
property :id, Integer, :serial => true
property :bidule_at, Time
property :read_at, Time, :nullable => true
end
Automigration created the table in mysql with the following code:
CREATE TABLE `tests` (`id` INT(11) NOT NULL AUTO_INCREMENT, `bidule_at` TIMESTAMP, `read_at` TIMESTAMP, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
t = Test.create() would do the following query
INSERT INTO `tests` () VALUES ()
Up until this everything is fine and work as expected
However any access to t.read_at would raise the following error:
ArgumentError: argument out of range
After a bit of investigation, it turns out that in the database the row was like this:
:id => 1, :bidule_at => 2008-06-03 22:13:51, :read_at => 0000-00-00 00:00:00
By the way, I was surprised that at least my mysql installation automatically treats the first timestamp column as if it was created with default CURRENT_TIMESTAMP even though it's not the case.
However, the second one would always be 0000-00-00 00:00:00 if I did not assign any value to it and the parsetime method from do_mysql would call Time.local(0,0,0,0,0,0,0) which would raise the error.
I have a patch that solves the problem along with the spec that tests the problem on my machine
You can pull it with git pull git://github.com/giom/do.git time_patch
Comments and changes to this ticket
-
Adam French June 10th, 2008 @ 12:27 PM
- State changed from new to resolved
I just applied this patch. Thanks a bunch, Guillaume!
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.