This project is archived and is in readonly mode.
to_xml datetime format regression
Reported by Mike Dvorkin | December 1st, 2010 @ 05:25 AM
Rails 3.0.3 incorrectly formats datetime fields unless the record is reloaded from the database. The following gist provides the test case and possible fix: https://gist.github.com/722889
More info and Rails 3.0.0 comparison: https://gist.github.com/720887
Comments and changes to this ticket
-
Aditya Sanghi December 1st, 2010 @ 07:56 AM
- Importance changed from to Low
@Mike, Please send failing test and patch as per contributor's guide http://rails.lighthouseapp.com/projects/8994/sending-patches
-
Aaron Patterson December 8th, 2010 @ 11:07 PM
I've been investigating this, and it looks like if you set
ActiveRecord::Base.time_zone_aware_attributes
to true, the problem goes away.I checked out the v3.0.0 tag, and this test also fails in Rails 3.0.0.
Here is a video of the test failing on 3.0.0:
http://www.youtube.com/watch?v=nrrWA7c9L1c
Here is a video of the test passing with time zone aware attributes:
http://www.youtube.com/watch?v=Q3UV-oCEmP4
I'm not convinced that there has been a regression during Rails 3.0.x. I do agree this is strange behavior. Given the "time_zone_aware_attributes" method, I wonder if this strange behavior is expected? It seems to me "time_zone_aware_attributes" should always be set to true, shouldn't it?
-
Mike Dvorkin December 8th, 2010 @ 11:49 PM
Ah, and I was about to submit a patch :-). I'm happy with ActiveRecord::Base.time_zone_aware_attributes approach and it certainly makes sense to set it to true by default.
I haven't run the tests against 3.0.0 so it's hard to say why they fail without looking into it (maybe Base.time_zone_aware_attributes should be explicitly set). But in any case, I've noticed this whole formatting discrepancy because of failing specs in my app after Rails 3.0.3 upgrade.
-
Espen Antonsen December 9th, 2010 @ 03:18 AM
Seems ActiveRecord::Base.time_zone_aware_attributes is set to true by default. But I still get the error when it is set to true as it was in my project.
Adding 'raw_value = raw_value.in_time_zone if raw_value.respond_to?(:in_time_zone)' as Mike suggests in his gist fixes the problem. But that is not necessary in 3.0.1 where this problem does not occur. Strange. What could be the cause? Also, as mention in ticket 6054 this problem does not occur with to_json. -
Espen Antonsen December 9th, 2010 @ 03:32 AM
Aaron: Your video of the test passing is marked as private. http://www.youtube.com/watch?v=Q3UV-oCEmP4
-
Mike Dvorkin December 9th, 2010 @ 04:29 AM
Aaron, unfortunately flipping ActiveRecord::Base.time_zone_aware_attributes doesn't seem to affect datetime formatting. Please see https://gist.github.com/734332 (view raw).
Let me follow-up with a patch...
-
Espen Antonsen December 9th, 2010 @ 04:34 AM
Mike: thanks for the update, but with your patch keep in mind that the fix you provided earlier by changing the value in ActiveModel::Serializers::Xml::Serializer::Attribute was not necessary in earlier versions. So I assume the problem must originate somewhere else?
-
Mike Dvorkin December 9th, 2010 @ 04:43 AM
- Tag changed from activemodel, to_xml to activemodel, patch, to_xml
Here's the patch ;-)
-
Repository December 9th, 2010 @ 08:07 AM
- State changed from new to resolved
(from [f572a02b94ce85bb8db64e838aa159cf3ef4b1fa]) Take into account current time zone when serializing datetime values [#6096 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
https://github.com/rails/rails/commit/f572a02b94ce85bb8db64e838aa15... -
Repository December 9th, 2010 @ 10:33 AM
(from [6dcde27f3aeb499b0776b447cde82c5e50fc8ede]) Take into account current time zone when serializing datetime values [#6096 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
https://github.com/rails/rails/commit/6dcde27f3aeb499b0776b447cde82...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 6054 DateTime in to_xml returns GMT from 3.0.2 oops, I meant a dup of #6096
- 6096 to_xml datetime format regression (from [f572a02b94ce85bb8db64e838aa159cf3ef4b1fa]) Take in...
- 6096 to_xml datetime format regression (from [6dcde27f3aeb499b0776b447cde82c5e50fc8ede]) Take in...
- 6054 DateTime in to_xml returns GMT from 3.0.2 I'm closing this as a duplicate of #6096