-
Notifications
You must be signed in to change notification settings - Fork 46
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
Introduce custom timezone configuration support for ActiveRecord enumerators #512
Introduce custom timezone configuration support for ActiveRecord enumerators #512
Conversation
8b98e4b
to
14f522a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just missing a change to enumerator_builder
to pass through the timezone
, LGTM otherwise.
Never mind, the splats take care of this. Good to merge! |
@@ -61,6 +62,7 @@ def column_value(record, attribute) | |||
value = record.read_attribute(attribute.to_sym) | |||
case record.class.columns_hash.fetch(attribute).type | |||
when :datetime | |||
value = value.in_time_zone(@timezone) unless @timezone.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this has to be configured explicitly. Active Job serializes and deserializes the timezone on the job, and sets it in an around_perform
hook. Could this simply be:
value.in_time_zone(::Time.zone)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that the default behaviour? I think the original issue is with a job enqueued (and running) in the local timezone, but reading data that was stored in a different time zone (UTC).
Background
Current implementation of
column_value
is prone to faulty serialisation if ActiveRecord's timezone differs from the timezone in the database.In our case, we are using
Eastern Time (US & Canada)
in our Rails application but our database stores datas inUTC
.Following console log demonstrates the issue:
Fix
Current implementation of
column_value
assumes that the database & the application are using the same timezone regardless of it being UTC or not. However, it is generally accepted that database column values that are of type date are assumed to be UTC unless explicitly stated otherwise. Therefore, any serialisation may assume as such instead of assuming them both having the same timezone.To make this change not potentially a breaking change we've made it configurable with a default value of
nil
. This will allow users of this library to configure a custom timezone if need be.