aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYasuo Honda <yasuo.honda@gmail.com>2018-10-23 07:29:26 +0000
committerYasuo Honda <yasuo.honda@gmail.com>2018-10-23 07:43:25 +0000
commit26369bbebf86570fad64032a7121a476019eb7f3 (patch)
tree8066ef3de78eb98902433305893b0722f07d8f20
parent759b3af0c6fc9fb502031a05b281736602ff8e5f (diff)
downloadrails-26369bbebf86570fad64032a7121a476019eb7f3.tar.gz
rails-26369bbebf86570fad64032a7121a476019eb7f3.tar.bz2
rails-26369bbebf86570fad64032a7121a476019eb7f3.zip
MySQL 8.0.13 raises `ER_NO_REFERENCED_ROW` and `ER_ROW_IS_REFERENCED`
when user has no parent table access privileges Refer https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html#mysqld-8-0-13-errors >> * Previously, the ER_NO_REFERENCED_ROW_2 and ER_ROW_IS_REFERENCED_2 error messages for foreign key operations were displayed and revealed information about parent tables, even when the user had no parent table access privileges. Error handling for this situation has been revised: * If the user does have table-level privileges for all parent tables, ER_NO_REFERENCED_ROW_2 and ER_ROW_IS_REFERENCED_2 are displayed, the same as before. * If the user does not have table-level privileges for all parent tables, more generic error messages are displayed instead (ER_NO_REFERENCED_ROW and ER_ROW_IS_REFERENCED). << This pull request addresses these 3 failures: ```ruby $ ARCONN=mysql2 bundle exec ruby -w -Itest test/cases/adapter_test.rb -n /foreign/ Using mysql2 Run options: -n /foreign/ --seed 14251 F Failure: ActiveRecord::AdapterForeignKeyTest#test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false [test/cases/adapter_test.rb:348]: [ActiveRecord::InvalidForeignKey] exception expected, not Class: <ActiveRecord::StatementInvalid> Message: <"Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails: INSERT INTO `fk_test_has_fk` (`fk_id`) VALUES (1231231231)"> ... snip ... rails test test/cases/adapter_test.rb:343 F Failure: ActiveRecord::AdapterForeignKeyTest#test_foreign_key_violations_on_delete_are_translated_to_specific_exception [test/cases/adapter_test.rb:368]: [ActiveRecord::InvalidForeignKey] exception expected, not Class: <ActiveRecord::StatementInvalid> Message: <"Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails: DELETE FROM fk_test_has_pk WHERE pk_id = 1"> ... snip ... rails test test/cases/adapter_test.rb:365 F Failure: ActiveRecord::AdapterForeignKeyTest#test_foreign_key_violations_on_insert_are_translated_to_specific_exception [test/cases/adapter_test.rb:358]: [ActiveRecord::InvalidForeignKey] exception expected, not Class: <ActiveRecord::StatementInvalid> Message: <"Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails: INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"> ... snip ... rails test test/cases/adapter_test.rb:357 Finished in 0.087370s, 34.3366 runs/s, 34.3366 assertions/s. 3 runs, 3 assertions, 3 failures, 0 errors, 0 skips $ ```
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb4
1 files changed, 3 insertions, 1 deletions
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 cb5eeb64dd..0f73641369 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -624,6 +624,8 @@ module ActiveRecord
# See https://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
ER_DUP_ENTRY = 1062
ER_NOT_NULL_VIOLATION = 1048
+ ER_NO_REFERENCED_ROW = 1216
+ ER_ROW_IS_REFERENCED = 1217
ER_DO_NOT_HAVE_DEFAULT = 1364
ER_ROW_IS_REFERENCED_2 = 1451
ER_NO_REFERENCED_ROW_2 = 1452
@@ -640,7 +642,7 @@ module ActiveRecord
case error_number(exception)
when ER_DUP_ENTRY
RecordNotUnique.new(message)
- when ER_ROW_IS_REFERENCED_2, ER_NO_REFERENCED_ROW_2
+ when ER_NO_REFERENCED_ROW, ER_ROW_IS_REFERENCED, ER_ROW_IS_REFERENCED_2, ER_NO_REFERENCED_ROW_2
InvalidForeignKey.new(message)
when ER_CANNOT_ADD_FOREIGN
mismatched_foreign_key(message)