Forum: Ruby on Rails ActionWebService date casting error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
87f3caa6600d95f06fdc00b822ed108d?d=identicon&s=25 Justin Johnson (Guest)
on 2006-03-28 18:06
(Received via mailing list)
I have defined a web service to return information from a database as
follows.

class BackendApi < ActionWebService::API::Base
  api_method :find_all_vobs,
             :returns => [[:int]]

  api_method :find_vob_by_id,
             :expects => [:int],
             :returns => [Vob]

class BackendController < ApplicationController
  wsdl_service_name 'Backend'
  web_service_scaffold :invoke

  def find_all_vobs
    Vob.find(:all).map{ |v| v.id }
  end

  def find_vob_by_id(id)
    Vob.find(id)
  end
end


mysql> describe vobs;
+-------------------------+---------------+------+-----+---------------------+----------------+
| Field                   | Type          | Null | Key | Default
      | Extra          |
+-------------------------+---------------+------+-----+---------------------+----------------+
| id                      | int(11)       |      | PRI | NULL
      | auto_increment |
| replica_family_uuid     | varchar(100)  |      |     |
      |                |
| created_by              | varchar(100)  |      |     |
      |                |
| created_on              | datetime      |      |     | 0000-00-00
00:00:00 |                |
| server_host             | varchar(50)   |      |     |
      |                |
| tag                     | varchar(50)   |      |     |
      |                |
| replica_name            | varchar(150)  |      |     |
      |                |
| master_replica          | varchar(150)  |      |     |
      |                |
| region                  | varchar(50)   |      |     |
      |                |
| owner                   | varchar(20)   |      |     |
      |                |
| primary_group           | varchar(20)   |      |     |
      |                |
| feature_level           | varchar(5)    |      |     |
      |                |
| database_schema_version | varchar(5)    |      |     |
      |                |
| access                  | varchar(10)   |      |     |
      |                |
| identity_preserving     | tinyint(1)    |      |     | 0
      |                |
| permission_preserving   | tinyint(1)    |      |     | 0
      |                |
| replica_names           | text          |      |     |
      |                |
| global_path             | varchar(150)  |      |     |
      |                |
| space_used              | decimal(10,2) |      |     | 0.00
      |                |
+-------------------------+---------------+------+-----+---------------------+----------------+
19 rows in set (0.00 sec)

When I connect via http://localhost:3000/backend/invoke (using the web
service scaffolding) FindAllVobs works as expected, but FindVobById
returns an error as seen below.  The date that "parse" is puking on in
the database is set to '2001-10-15 10:41:41'.


ArgumentError in Backend#invoke_submit
invalid date

c:/ruby/lib/ruby/1.8/date.rb:1214:in `new_with_hash'
c:/ruby/lib/ruby/1.8/date.rb:1258:in `parse'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:103:in
`cast_base_type'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:62:in
`cast'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:123:in
`cast_to_structured_type'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:121:in
`each_member'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/support/signature_types.rb:205:in
`each'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/support/signature_types.rb:205:in
`each_member'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:121:in
`cast_to_structured_type'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:60:in
`cast'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:38:in
`cast_returns'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/casting.rb:25:in
`cast_returns'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/api.rb:193:in
`cast_returns'
c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-1.0.0.4008/lib/action_web_service/dispatcher/abstract.rb:182:in
`web_service_create_response'
.
.
.


The book Agile Web Development with Rails seems to indicate that this
should just work the way I have set it up.  Does anyone have any
suggestions as to what I should be looking for to solve this?   I'm
running the Rails 1.1 candidate from the gems on Windows XP with Ruby
1.8.2.

Thanks,
Justin
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-03-28 18:48
(Received via mailing list)
Have you tried to upgrade your Rails to 1.1?

Kent
87f3caa6600d95f06fdc00b822ed108d?d=identicon&s=25 Justin Johnson (Guest)
on 2006-03-28 19:53
(Received via mailing list)
I updated to Rails 1.1 and Ruby 1.8.4 preview 3 (latest one click
installer for Windows) and now I get the following error.  It appears
to be the same error but more informative.

ArgumentError in Backend#invoke_submit
3 elements of civil date are necessary
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-03-28 21:45
(Received via mailing list)
I've just noticed the default value for your created_on column. It all
comes to:

$ irb
irb(main):001:0> require 'date'
=> true
irb(main):002:0> Date.parse('0000-00-00 00:00:00')
ArgumentError: invalid date
        from /usr/local/lib/ruby/1.8/date.rb:591:in `civil'
        from /usr/local/lib/ruby/1.8/date.rb:652:in `new_with_hash'
        from /usr/local/lib/ruby/1.8/date.rb:695:in `parse'
        from (irb):2
        from :0
irb(main):003:0>

Kent.

On 3/28/06, Justin Johnson <justinj@justinj.org> wrote:
> >
> >              :returns => [[:int]]
> >     Vob.find(:all).map{ |v| v.id }
> > | Field                   | Type          | Null | Key | Default
> > | server_host             | varchar(50)   |      |     |
> >       |                |
> > | permission_preserving   | tinyint(1)    |      |     | 0
> > When I connect via http://localhost:3000/backend/invoke
> > c:/ruby/lib/ruby/1.8/date.rb:1258:in `parse'
> > c:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-
> > 1.0.0.4008/lib/action_web_service/casting.rb:38:in
> > .
> >
> > Kent
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
Kent
---
http://www.datanoise.com
87f3caa6600d95f06fdc00b822ed108d?d=identicon&s=25 Justin Johnson (Guest)
on 2006-03-28 22:23
(Received via mailing list)
self._parse in date/format.rb starting on line 250 doesn't match the
year
for some reason, leaving elem[:year] set to nil.  Then
self.new_with_hashfails at line 1213 of
date.rb because year (which it extracted from elem[:year]) is nil.
Eaad83277bf09037d590b297b5aa8d57?d=identicon&s=25 Justin Johnson (justinj)
on 2006-03-29 20:22
Can someone tell me if the following works for you?  This is what is
happening in cast_base_type in
actionwebservice-1.1.0\lib\action_web_service\casting.rb line 105.

C:\>irb

irb(main):001:0> require 'date'
=> true

irb(main):002:0> Time.now
=> Wed Mar 29 12:16:09 Central Standard Time 2006
irb(main):003:0> DateTime.parse Time.now.to_s
ArgumentError: 3 elements of civil date are necessary
        from c:/ruby/lib/ruby/1.8/date.rb:1214:in `new_with_hash'
        from c:/ruby/lib/ruby/1.8/date.rb:1258:in `parse'
        from (irb):3
irb(main):004:0>
87f3caa6600d95f06fdc00b822ed108d?d=identicon&s=25 Justin Johnson (Guest)
on 2006-03-29 20:33
(Received via mailing list)
Can someone tell me if the following works for you?  This is what is
happening in cast_base_type in
actionwebservice-1.1.0\lib\action_web_service\casting.rb line 105.

C:\>irb
irb(main):001:0> require 'date'
=> true
irb(main):002:0> Time.now
=> Wed Mar 29 12:16:09 Central Standard Time 2006
irb(main):003:0> DateTime.parse Time.now.to_s
ArgumentError: 3 elements of civil date are necessary
        from c:/ruby/lib/ruby/1.8/date.rb:1214:in `new_with_hash'
        from c:/ruby/lib/ruby/1.8/date.rb:1258:in `parse'
        from (irb):3
irb(main):004:0>
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Daniel Berger (Guest)
on 2006-03-29 20:52
(Received via mailing list)
Justin Johnson wrote:
> => Wed Mar 29 12:16:09 Central Standard Time 2006
> irb(main):003:0> DateTime.parse Time.now.to_s
> ArgumentError: 3 elements of civil date are necessary
>         from c:/ruby/lib/ruby/1.8/date.rb:1214:in `new_with_hash'
>         from c:/ruby/lib/ruby/1.8/date.rb:1258:in `parse'
>         from (irb):3
> irb(main):004:0>
>

It's a bug in DateTime.parse specific to Windows.  It's caused by the
long time
  zone string, i.e. "Central Standard Time" instead of "CST".

It's fixed in the Ruby 1.9 branch.  Whether or not you can just copy
date.rb
into your stdlib, I'm not sure.

Regards,

Dan
Eaad83277bf09037d590b297b5aa8d57?d=identicon&s=25 Justin Johnson (justinj)
on 2006-03-29 21:03
Thank you!
8f23570fbde6277118fcd088a675f61a?d=identicon&s=25 Josh (Guest)
on 2006-04-25 17:38
Was anyone able to find a workaround for this problem?  Does using the
date.rb file for 1.9 work?  If so, where can I find this -- I was unable
to find the 1.9 branch in the CVS repository.

Thanks!

Justin Johnson wrote:
> Thank you!
813679171280808f051b5754c9db45a6?d=identicon&s=25 Wes Ratcliff (Guest)
on 2006-04-30 17:38
I'd love to know as well... I dropped date.rb, date2.rb and
date/format.rb from the 1.9 branch into my 1.8 directory but still had
the same problem!

Josh wrote:
> Was anyone able to find a workaround for this problem?  Does using the
> date.rb file for 1.9 work?  If so, where can I find this -- I was unable
> to find the 1.9 branch in the CVS repository.
>
> Thanks!
>
> Justin Johnson wrote:
>> Thank you!
This topic is locked and can not be replied to.