Skip to content

Commit c1ff85f

Browse files
Edouard-chinbyroot
authored andcommitted
Fix column_definition returning a wrong column:
- The issue was introduced in 9ad36e0. Now that a Column includes its cast type, the deduplicable feature that checks whether we have a colum in the cache would wrongly return an existing column that have the same type. https://github.com/rails/rails/blob/2ca006fb7fe881c225c000d9ab11e2a3554b70fa/activerecord/lib/active_record/connection_adapters/deduplicable.rb#L19 https://github.com/rails/rails/blob/2ca006fb7fe881c225c000d9ab11e2a3554b70fa/activerecord/lib/active_record/connection_adapters/column.rb#L81 And because the Type::DateTime doesn't override `==`, 2 Type::DateTime objects would return true regardless of their timezone.
1 parent 59a42a9 commit c1ff85f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

activerecord/lib/active_record/type/internal/timezone.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def is_utc?
1616
def default_timezone
1717
@timezone || ActiveRecord.default_timezone
1818
end
19+
20+
def ==(other)
21+
super(other) && timezone == other.timezone
22+
end
23+
24+
protected
25+
attr_reader :timezone
1926
end
2027
end
2128
end

activerecord/test/cases/base_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,4 +1982,12 @@ def test_protected_environments_are_stored_as_an_array_of_string
19821982
assert_not ActiveRecord::Base.current_preventing_writes
19831983
end
19841984
end
1985+
1986+
private
1987+
def with_timezone_config(cfg, &block)
1988+
super(cfg) do
1989+
Default.reset_column_information
1990+
block.call
1991+
end
1992+
end
19851993
end

0 commit comments

Comments
 (0)