Sunday, October 16, 2011

Mysql2::Error (Invalid date: xx) on a text field?!

I have this rule, the longer it takes to figure out a bug, the dumber the solution is going to be. This one was no exception.This bug on the rails adapter for mysql (the native Mysql2 for Windows) cost me a day and a half of bewilderment.

The symptoms were that when populating a particular field in a table caused the created_at filed that was directly after to corrupt.
Although the entry would save successfully, once i tried to retrieve it, it would omit an argument error, without  any explanations  or indication to the field that was causing the problem.

After literally hours spent reinstalling and reconfiguring and redeploying my application and the run times involves i stumbled upon this error "Mysql2::Error (Invalid date: xx)" where xx was the text value of the field preceding the "created_at" standard field.
A quick search on Google pointed me to the bug in Mysql2.

My solution was (cross my heart and hope to die) was to add an extra field that i never populate before the date fields.

Good Luck.