diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-10-29 09:37:01 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-10-29 09:43:56 +0100 |
commit | 82ce157844f38ac144e2185786f8875df07a7a37 (patch) | |
tree | 17787a102cfde0c257811704c84b07f85ef29309 /activerecord | |
parent | e595d91ac2c07371b441f8b04781e7c03ac44135 (diff) | |
download | rails-82ce157844f38ac144e2185786f8875df07a7a37.tar.gz rails-82ce157844f38ac144e2185786f8875df07a7a37.tar.bz2 rails-82ce157844f38ac144e2185786f8875df07a7a37.zip |
fix MySQL enum type lookup with values matching another type. Closes #17402.
The MySQLAdapter type map used the lowest priority for enum types.
This was the result of a recent refactoring and lead to some broken lookups
for enums with values that match other types. Like `8bit`.
This patch restores the priority to what we had before the refactoring.
/cc @sgrif
Diffstat (limited to 'activerecord')
3 files changed, 17 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 79dc390f0a..ad4ee0f489 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* MySQL enum type lookups, with values matching another type, no longer result + in an endless loop. + + Fixes #17402. + + *Yves Senn* + * Raise `ArgumentError` when the body of a scope is not callable. *Mauro George* diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index c5dd93ee89..9077a9cfe3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -656,12 +656,6 @@ module ActiveRecord def initialize_type_map(m) # :nodoc: super - m.register_type(%r(enum)i) do |sql_type| - limit = sql_type[/^enum\((.+)\)/i, 1] - .split(',').map{|enum| enum.strip.length - 2}.max - Type::String.new(limit: limit) - end - m.register_type %r(tinytext)i, Type::Text.new(limit: 2**8 - 1) m.register_type %r(tinyblob)i, Type::Binary.new(limit: 2**8 - 1) m.register_type %r(text)i, Type::Text.new(limit: 2**16 - 1) @@ -682,6 +676,12 @@ module ActiveRecord m.alias_type %r(set)i, 'varchar' m.alias_type %r(year)i, 'integer' m.alias_type %r(bit)i, 'binary' + + m.register_type(%r(enum)i) do |sql_type| + limit = sql_type[/^enum\((.+)\)/i, 1] + .split(',').map{|enum| enum.strip.length - 2}.max + Type::String.new(limit: limit) + end end # MySQL is too stupid to create a temporary table for use subquery, so we have diff --git a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb index d4d67487db..80244d1439 100644 --- a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb +++ b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb @@ -22,6 +22,10 @@ module ActiveRecord assert_lookup_type :string, "SET('one', 'two', 'three')" end + def test_enum_type_with_value_matching_other_type + assert_lookup_type :string, "ENUM('unicode', '8bit', 'none')" + end + def test_binary_types assert_lookup_type :binary, 'bit' assert_lookup_type :binary, 'BIT' |