surprised by (lack of) date validation ....

45 views
Skip to first unread message

storitel

unread,
Jul 23, 2010, 3:08:40 PM7/23/10
to Hobo Users
it seems that if i select 31st Sept as a date in a hobo app field it
triggers an exception, rather than a "please enter a valid date".

obviously this suggests rails and/or ruby understands that there are
only 30 days in September at some level - but i don't understand why
it throws an exception, rather than rounding it to the nearest valid
date.

If I enter "Fred" in an integer field I get zero, for example.

Notwithstanding the above, I installed the validates_timeliness gem,
added a valdidates_date, and expected the problem to go away....

Amazingly, same result. validates_timeliness also happily lets the
invalid_date exception occur. surely i'm not the first to hit this? is
it because i'm in a euro timezone?

Owen

unread,
Jul 23, 2010, 4:07:05 PM7/23/10
to Hobo Users
I don't remember that issue before Internationalization support was
added, but I could be way off. : -)

What version of Hobo and Rails are you using?

Interesting take on this:
http://www.railway.at/articles/2008/08/01/to-raise-or-not-to-raise/

Owen

unread,
Jul 23, 2010, 5:06:30 PM7/23/10
to Hobo Users
I am getting the same issue. Don't remember this before 1.0, but I
could be wrong...

-Owen

Matt Jones

unread,
Jul 23, 2010, 5:16:19 PM7/23/10
to hobo...@googlegroups.com
On Fri, Jul 23, 2010 at 3:08 PM, storitel <stor...@gmail.com> wrote:
> it seems that if i select 31st Sept as a date in a  hobo app field it
> triggers an exception, rather than a "please enter a valid date".
>
> obviously this suggests rails and/or ruby understands that there are
> only 30 days in September at some level - but i don't understand why
> it throws an exception, rather than rounding it to the nearest valid
> date.

I've run across this before, even in plain Rails. However, the last
time I looked at this date_select was still generating the old-style
1i,2i,3i fields instead of the current behavior.

Oddly enough, datetime fields don't have this problem - trying to put
a date of "February 31" into a datetime field just gets me back March
3...

--Matt Jones

Owen Dall

unread,
Jul 23, 2010, 5:32:50 PM7/23/10
to hobo...@googlegroups.com
So, an easy workaround is to use datetime...


--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.




--
- Owen

Owen Dall, Chief Systems Architect
Barquin International
Cell: 410-991-0811

Owen

unread,
Jul 23, 2010, 6:07:41 PM7/23/10
to Hobo Users
Works, but is kludgy:

http://screencast.com/t/OGQzOGRh

Nest release needs to use a JQuery datapicker by default...

On Jul 23, 5:32 pm, Owen Dall <od...@barquin.com> wrote:
> So, an easy workaround is to use datetime...
>
>
>
>
>
> On Fri, Jul 23, 2010 at 5:16 PM, Matt Jones <al2o...@gmail.com> wrote:
> > On Fri, Jul 23, 2010 at 3:08 PM, storitel <stori...@gmail.com> wrote:
> > > it seems that if i select 31st Sept as a date in a  hobo app field it
> > > triggers an exception, rather than a "please enter a valid date".
>
> > > obviously this suggests rails and/or ruby understands that there are
> > > only 30 days in September at some level - but i don't understand why
> > > it throws an exception, rather than rounding it to the nearest valid
> > > date.
>
> > I've run across this before, even in plain Rails. However, the last
> > time I looked at this date_select was still generating the old-style
> > 1i,2i,3i fields instead of the current behavior.
>
> > Oddly enough, datetime fields don't have this problem - trying to put
> > a date of "February 31" into a datetime field just gets me back March
> > 3...
>
> > --Matt Jones
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Hobo Users" group.
> > To post to this group, send email to hobo...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > hobousers+...@googlegroups.com<hobousers%2Bunsubscribe@googlegroups .com>
> > .

storitel

unread,
Jul 23, 2010, 6:20:57 PM7/23/10
to Hobo Users
I had been using the datepicker, but had to drop it because the format
order wasn't always being picked up properly. once i get the agility/
selenium setup running i will try to replicate that...

meantime, i guess this *is* a bug? if it's a problem in rails/
validates_timeliness, it's even more surprising...

Matt Jones

unread,
Jul 25, 2010, 9:03:30 PM7/25/10
to hobo...@googlegroups.com

On Jul 23, 2010, at 6:20 PM, storitel wrote:

> I had been using the datepicker, but had to drop it because the format
> order wasn't always being picked up properly. once i get the agility/
> selenium setup running i will try to replicate that...
>
> meantime, i guess this *is* a bug? if it's a problem in rails/
> validates_timeliness, it's even more surprising...

Looks like we either need to borrow the Rails fallback code for this,
or figure out how to get out the attribute parsing business entirely.
Here's how Rails avoids the error:

begin
values = values_with_empty_parameters.collect do |
v| v.nil? ? 1 : v end
Date.new(*values)
rescue ArgumentError => ex # if Date.new raises an
exception on an invalid date
instantiate_time_object(name, values).to_date # we
instantiate Time object and convert it back to a date thus using
Time's logic in handling invalid dates
end

I was kind of disappointed when I found this; I was hoping there was a
slightly more glamorous solution than just swallowing the exception
and punting. Apparently not. :)

Tom, Bryan - do either of you recall why we're manually parsing those
attributes in convert_type_for_mass_assignment? Is it still needed in
2.3?

--Matt Jones

storitel

unread,
Jul 26, 2010, 2:06:09 AM7/26/10
to Hobo Users
not sure if it helps, but Adam the author of validates_timeliness has
this to say

From the stack trace it appears that the plugin parser is not being
used.
I think the plugin is not compatible with Hobo for some reason.
My guess is that Hobo is overriding something in ActiveRecord and
removing the plugin hooks which is preventing its proper operation.

http://github.com/adzap/validates_timeliness/issues/issue/12/#issue/12/comment/326416

Owen

unread,
Jul 26, 2010, 5:56:53 PM7/26/10
to Hobo Users
Thanks for tracking that down. We need to either get the plugin to
work or to provide a reliable alternative...

On Jul 26, 2:06 am, storitel <stori...@gmail.com> wrote:
> not sure if it helps, but Adam the author of validates_timeliness has
> this to say
>
> From the stack trace it appears that the plugin parser is not being
> used.
> I think the plugin is not compatible with Hobo for some reason.
> My guess is that Hobo is overriding something in ActiveRecord and
> removing the plugin hooks which is preventing its proper operation.
>
> http://github.com/adzap/validates_timeliness/issues/issue/12/#issue/1...

Daniel Cox

unread,
Sep 20, 2011, 7:24:36 PM9/20/11
to hobo...@googlegroups.com
Did anyone eventually figure this out? I'm having the exact same problem (with the exception raised by date.rb right after convert_type_for_mass_assignment), in Hobo 1.3.0.RC2 and Rails 3.0.10. I was getting this error before installing validates_timeliness, which failed to solve the problem for me.

dklopp

unread,
Sep 21, 2011, 8:53:22 AM9/21/11
to hobo...@googlegroups.com

Or you could rewrite convert_type_for_mass_assignment to handle invalid dates. (Put something like the attachment in ..\config\initializers)

convert_type_for_mass_assignment.rb

Daniel Cox

unread,
Sep 21, 2011, 11:48:46 AM9/21/11
to hobo...@googlegroups.com
Thanks. The thread wasn't very helpful and the code crashed on initialization, but I get the idea and I may try to fix this later. Perhaps someone should submit the issue to the hobo developers?

Matt Jones

unread,
Sep 21, 2011, 12:19:42 PM9/21/11
to hobo...@googlegroups.com

On Sep 21, 2011, at 11:48 AM, Daniel Cox wrote:

> Thanks. The thread wasn't very helpful and the code crashed on initialization, but I get the idea and I may try to fix this later. Perhaps someone should submit the issue to the hobo developers?

Oh, we know. :)

For 1.3, the resolution is likely to be only partial - I think it should be practical to at least get the thing to not blow up. Invalid dates will likely turn to blanks, though.

Post-1.3, I suspect the solution will be to get out of the multiparameter-parsing business entirely; Rails does it better internally, it'd be more compatible with other plugins, etc.

--Matt Jones

Daniel Cox

unread,
Sep 21, 2011, 12:21:55 PM9/21/11
to hobo...@googlegroups.com
:) Thanks. Sounds good.

Owen Dall

unread,
Sep 21, 2011, 1:25:29 PM9/21/11
to hobo...@googlegroups.com
Good idea, Matt.
 
-Owen

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.




--
Owen Dall, Chief Systems Architect
Barquin International

Matt Jones

unread,
Sep 25, 2011, 7:26:07 PM9/25/11
to hobo...@googlegroups.com

On Sep 21, 2011, at 8:53 AM, dklopp wrote:

> You could check this thread https://groups.google.com/forum/#!msg/hobousers/ofT7uwObOHc/ja1c2A809eEJ
>
> Or you could rewrite convert_type_for_mass_assignment to handle invalid dates. (Put something like the attachment in ..\config\initializers)
>

Code similar to this is now in the rails3 branch. The one gotcha is that it now handles invalid dates by converting them to equivalent valid dates - thus, setting a field to February 31 will actually result in March 3 being stored. This is identical to the behavior of the default Rails helpers, and is at least less user-hostile than blowing up with a 500 page.

--Matt Jones

Reply all
Reply to author
Forward
0 new messages