validates_timeliness icon indicating copy to clipboard operation
validates_timeliness copied to clipboard

Check time_zone_aware_types

Open codez opened this issue 3 years ago • 3 comments

When testing if a certain attribute is time zone aware in the validator, also check the value of ActiveRecord::Base.time_zone_aware_types.

We have ActiveRecord::Base.time_zone_aware_types = [:datetime], hence :time types are not time zone aware. When validating times, they are still converted to CET, giving wrong validation errors.

This problem arised with the upgrade to 5.0, because skip_time_zone_conversion_for_attributes is empty in our case, which leads to the attribute being interpreted as time zone aware wrongly. In version 4.1, timeliness_attribute_timezone_aware? returned false by default.

codez avatar Jun 02 '21 15:06 codez

What version of Rails/ActiveRecord are you using?

adzap avatar Jun 04 '21 06:06 adzap

6.1.3.2

codez avatar Jun 04 '21 08:06 codez

Hi, I have this same problem because we have disabled time zone award system-wide with the config option config.active_record.time_zone_aware_attributes = false and because the method time_zone_aware? in validator.rb here does not check if this config flag is false and then return true, making the parsing wrong.

I wrote a patch PR for this #202

camilova avatar Sep 20 '21 14:09 camilova