Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psych 1.2.1 not Compatible with Ruby 1.9.2 #32

Closed
aselder opened this issue Oct 3, 2011 · 4 comments
Closed

Psych 1.2.1 not Compatible with Ruby 1.9.2 #32

aselder opened this issue Oct 3, 2011 · 4 comments

Comments

@aselder
Copy link

aselder commented Oct 3, 2011

I just upgraded to Psych 1.2.1 and ran into a problem with serializing times in my Rails app. Essentially serialize/deserialize roundtrips were losing their timezone information.

A look at my rails log shows some weirdness:

INSERT INTO etl_logs (job_name, last_run_date, last_run_time, last_run, rows_processed, job_errors, rows_imported, run_time, stats, created_at, updated_at, additional_data, hostname, pid) VALUES('Incremental import of TT tickets', '2011-10-03', '2011-10-03 12:19:58', '2011-10-03 12:19:58', NULL, 0, NULL, 0, NULL, '2011-10-03 12:22:17', '2011-10-03 12:22:17', '---\n:timestamp: 0.040103\n:svn_version: $HeadURL$\n:svn_rev: $Rev$\n:version_txt: $HeadURL$\n:start_job_time: 0.013328075408935547\n:start_job_calls: 1\n:updating_running_jobs_time: 0.0029239654541015625\n:updating_running_jobs_calls: 1\n:get_job_datetime_time: 9.489059448242188e-05\n:get_job_datetime_calls: 1\n:etl_errors: 1\n:tt_incr_skipped_increments: 1\n:soft_aborts: 1\n:parse_time: 0.031224966049194336\n:parse_calls: 1\n:max_ticket_timestamp: 2011-10-03 18:43:58.667334000 %:z\n:tt_import_next_params:\n :last_timestamp: 2011-10-03 18:43:58.667334000 %:z\n :next_row: 1\n :max_rows: 2000\n :job_type: :incremental\n:start_job_average_time: 0.013328075408935547\n:updating_running_jobs_average_time: 0.0029239654541015625\n:get_job_datetime_average_time: 9.489059448242188e-05\n:parse_average_time: 0.031224966049194336\n', 'eds-big-laptop.lan', 82462)

Note the :last_timestamp field about 3/4 of the way through; it ends "%:z" rather than the UTC offset..

A quick grep and the culprit is found in lib/psych/visitors/yaml_tree.rb line 311. There is a spare colon hanging around in the format string of the strftime.

I'll have a patch with tests shortly.

@aselder
Copy link
Author

aselder commented Oct 3, 2011

In fact, Psych's own test suite fails:

  1. Failure:
    test_datetime(Psych::JSON::TestStream) [/Users/andrew/Dropbox/FanSnap/psych/test/psych/json/test_stream.rb:105]:
    Expected /{"a":\ "2010-10-10\ 00:00:00.000000000\ -07:00"}\n/ to match "--- {"a": "2010-10-10 00:00:00.000000000 %:z"}\n...\n".

  2. Failure:
    test_round_trip(Psych::TestDateTime) [/Users/andrew/Dropbox/FanSnap/psych/test/psych/test_date_time.rb:14]:
    Expected #<DateTime: 2011-10-03T12:41:41-07:00 (212184430901295871/86400000000,-7/24,2299161)>, not #<DateTime: 2011-10-03T05:41:41-07:00 (212184405701295871/86400000000,-7/24,2299161)>.

  3. Failure:
    test_datetime(Psych::TestJSONTree) [/Users/andrew/Dropbox/FanSnap/psych/test/psych/test_json_tree.rb:62]:
    Expected "{"a": "2010-10-10 00:00:00.000000000 -07:00"}\n", not "{"a": "2010-10-10 00:00:00.000000000 %:z"}\n".

  4. Failure:
    test_time(Psych::Visitors::TestYAMLTree) [/Users/andrew/Dropbox/FanSnap/psych/test/psych/visitors/test_yaml_tree.rb:63]:
    Expected 2011-10-03 12:41:41 -0700, not 2011-10-03 05:41:41 -0700.

  5. Failure:
    test_time_now_cycle(Psych_Unit_Tests) [/Users/andrew/Dropbox/FanSnap/psych/test/psych/test_yaml.rb:1175]:
    Expected 2011-10-03 12:41:41 -0700, not 2011-10-03 05:41:41 -0700.

@aselder
Copy link
Author

aselder commented Oct 3, 2011

I'm running on Ruby 1.9.2-p290. Looking at things (http://redmine.ruby-lang.org/issues/3778), it looks like the %:z specifier in strftime is only defined in Ruby 1.9.3 and higher.

This means that Psych 1.2.1 does not work and in fact, can screw things up pretty badly in Ruby 1.9.2 and earlier.

@aselder
Copy link
Author

aselder commented Oct 3, 2011

In addition, the lib/psych/visitors/to_ruby.rb file references the constant Regexp::NOENCODING which is not defined in Ruby 1.9.2, it makes it's appearance in Ruby 1.9.3

I don't think this is a huge problem other than a failing spec, as in Ruby 1.9.2 you can't create a regex with the noencoding flag in 1.9.2. It would cause an exception if a YAML file was generated on Ruby 1.9.3 and then parsed in Ruby 1.9.2.

@tenderlove
Copy link
Member

This was fixed in 1.2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants