From 0f30d0a261a11ceb469d748cc37152b86a95b3c5 Mon Sep 17 00:00:00 2001 From: Connor Dunn Date: Thu, 9 Feb 2023 16:39:46 -0800 Subject: [PATCH] Spanner timestamp maps better to DateTime than Time Extending ActiveRecord::Type::Time means that string values get incorrectly coerced to have a date of 2000-01-01. See https://github.com/rails/rails/blob/main/activemodel/lib/active_model/type/time.rb#L14. This is because Time in activerecord is intended to store just the time value (and maps to a TIME type in other databases), unlike Time generally in ruby that represents a date and time.x --- lib/active_record/type/spanner/time.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_record/type/spanner/time.rb b/lib/active_record/type/spanner/time.rb index e47fa97d..b326250a 100644 --- a/lib/active_record/type/spanner/time.rb +++ b/lib/active_record/type/spanner/time.rb @@ -9,7 +9,7 @@ module ActiveRecord module Type module Spanner - class Time < ActiveRecord::Type::Time + class Time < ActiveRecord::Type::DateTime def serialize_with_isolation_level value, isolation_level if value == :commit_timestamp return "PENDING_COMMIT_TIMESTAMP()" if isolation_level == :dml