ActionWebService date casting error


#1

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:inparse’
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:incast’
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:ineach_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:ineach_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:incast’
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:incast_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:inweb_service_create_response’
.
.
.

The book Agile Web D. 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


#2

Have you tried to upgrade your Rails to 1.1?

Kent


#3

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


#4

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:innew_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 J. removed_email_address@domain.invalid 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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Kent

http://www.datanoise.com


#5

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.


#6

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:inparse’
from (irb):3
irb(main):004:0>


#7

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:inparse’
from (irb):3
irb(main):004:0>


#8

Justin J. 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:inparse’
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


#9

Thank you!


#10

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 J. wrote:

Thank you!


#11

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 J. wrote:

Thank you!