Issue #13791 has been updated by yahonda (Yasuo Honda).


Opened https://github.com/rails/rails/issues/30160

----------------------------------------
Bug #13791: `belongs_to': unknown keywords: required, anonymous_class (ArgumentError) since Revision 59519
https://bugs.ruby-lang.org/issues/13791#change-66103

* Author: yahonda (Yasuo Honda)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-08-05 diag2 59519) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Since Revision 59519, Rails ActiveRecord unit test fails with this error.

> /home/yahonda/git/rails/activerecord/lib/active_record/associations.rb:1669:in `belongs_to': unknown keywords: required, anonymous_class (ArgumentError)

### Steps to reproduce

$ git clone https://github.com/rails/rails.git
$ cd rails/activerecord
$ bundle
$ bundle exec rake test_sqlite3

### Result

```
$ bundle exec rake test_sqlite3
/home/yahonda/.rbenv/versions/2.5.0-dev_diag2/bin/ruby -w -I"lib:test" -I"/home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib" "/home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib/rake/rake_test_loader.rb" "test/cases/result_test.rb" "test/cases/modules_test.rb" "test/cases/log_subscriber_test.rb" "test/cases/pooled_connections_test.rb" "test/cases/locking_test.rb" "test/cases/nested_attributes_with_callbacks_test.rb" "test/cases/fixtures_test.rb" "test/cases/habtm_destroy_order_test.rb" "test/cases/scoping/relation_scoping_test.rb" "test/cases/scoping/default_scoping_test.rb" "test/cases/scoping/named_scoping_test.rb" "test/cases/custom_locking_test.rb" "test/cases/timestamp_test.rb" "test/cases/connection_management_test.rb" "test/cases/finder_respond_to_test.rb" "test/cases/comment_test.rb" "test/cases/migration/compatibility_test.rb" "test/cases/migration/change_schema_test.rb" "test/cases/migration/change_tabl
 e_test.rb" "test/cases/migration/references_index_test.rb" "test/cases/migration/create_join_table_test.rb" "test/cases/migration/references_statements_test.rb" "test/cases/migration/pending_migrations_test.rb" "test/cases/migration/logger_test.rb" "test/cases/migration/command_recorder_test.rb" "test/cases/migration/column_attributes_test.rb" "test/cases/migration/column_positioning_test.rb" "test/cases/migration/foreign_key_test.rb" "test/cases/migration/columns_test.rb" "test/cases/migration/index_test.rb" "test/cases/migration/references_foreign_key_test.rb" "test/cases/migration/rename_table_test.rb" "test/cases/clone_test.rb" "test/cases/database_statements_test.rb" "test/cases/inheritance_test.rb" "test/cases/invalid_connection_test.rb" "test/cases/attribute_set_test.rb" "test/cases/validations_test.rb" "test/cases/cache_key_test.rb" "test/cases/secure_token_test.rb" "test/cases/dirty_test.rb" "test/cases/time_precision_test.rb" "test/cases/invertible_migration_test.rb" "test
 /cases/date_test.rb" "test/cases/mixin_test.rb" "test/cases/integration_test.rb" "test/cases/connection_pool_test.rb" "test/cases/migration_test.rb" "test/cases/primary_keys_test.rb" "test/cases/schema_loading_test.rb" "test/cases/relations_test.rb" "test/cases/connection_specification/resolver_test.rb" "test/cases/persistence_test.rb" "test/cases/readonly_test.rb" "test/cases/multiple_db_test.rb" "test/cases/forbidden_attributes_protection_test.rb" "test/cases/binary_test.rb" "test/cases/attribute_methods/read_test.rb" "test/cases/migrator_test.rb" "test/cases/core_test.rb" "test/cases/type/adapter_specific_registry_test.rb" "test/cases/type/string_test.rb" "test/cases/type/unsigned_integer_test.rb" "test/cases/type/type_map_test.rb" "test/cases/type/date_time_test.rb" "test/cases/type/integer_test.rb" "test/cases/serialization_test.rb" "test/cases/defaults_test.rb" "test/cases/batches_test.rb" "test/cases/fixture_set/file_test.rb" "test/cases/attribute_methods_test.rb" "test/cases
 /test_fixtures_test.rb" "test/cases/column_alias_test.rb" "test/cases/relation/where_test.rb" "test/cases/relation/mutation_test.rb" "test/cases/relation/record_fetch_warning_test.rb" "test/cases/relation/predicate_builder_test.rb" "test/cases/relation/delegation_test.rb" "test/cases/relation/where_chain_test.rb" "test/cases/relation/where_clause_test.rb" "test/cases/relation/or_test.rb" "test/cases/relation/merging_test.rb" "test/cases/json_attribute_test.rb" "test/cases/explain_test.rb" "test/cases/aggregations_test.rb" "test/cases/touch_later_test.rb" "test/cases/reflection_test.rb" "test/cases/collection_cache_key_test.rb" "test/cases/sanitize_test.rb" "test/cases/i18n_test.rb" "test/cases/suppressor_test.rb" "test/cases/reserved_word_test.rb" "test/cases/null_relation_test.rb" "test/cases/nested_attributes_test.rb" "test/cases/type_test.rb" "test/cases/attribute_test.rb" "test/cases/multiparameter_attributes_test.rb" "test/cases/json_serialization_test.rb" "test/cases/query_cac
 he_test.rb" "test/cases/hot_compatibility_test.rb" "test/cases/explain_subscriber_test.rb" "test/cases/serialized_attribute_test.rb" "test/cases/transaction_callbacks_test.rb" "test/cases/transaction_isolation_test.rb" "test/cases/adapter_test.rb" "test/cases/coders/yaml_column_test.rb" "test/cases/coders/json_test.rb" "test/cases/attribute_decorators_test.rb" "test/cases/reload_models_test.rb" "test/cases/ar_schema_test.rb" "test/cases/reaper_test.rb" "test/cases/counter_cache_test.rb" "test/cases/column_definition_test.rb" "test/cases/attributes_test.rb" "test/cases/view_test.rb" "test/cases/transactions_test.rb" "test/cases/base_test.rb" "test/cases/types_test.rb" "test/cases/finder_test.rb" "test/cases/autosave_association_test.rb" "test/cases/associations_test.rb" "test/cases/store_test.rb" "test/cases/errors_test.rb" "test/cases/numeric_data_test.rb" "test/cases/connection_adapters/mysql_type_lookup_test.rb" "test/cases/connection_adapters/adapter_leasing_test.rb" "test/cases/
 connection_adapters/merge_and_resolve_default_url_config_test.rb" "test/cases/connection_adapters/schema_cache_test.rb" "test/cases/connection_adapters/type_lookup_test.rb" "test/cases/connection_adapters/connection_handler_test.rb" "test/cases/connection_adapters/connection_specification_test.rb" "test/cases/validations/uniqueness_validation_test.rb" "test/cases/validations/i18n_generate_message_validation_test.rb" "test/cases/validations/association_validation_test.rb" "test/cases/validations/absence_validation_test.rb" "test/cases/validations/presence_validation_test.rb" "test/cases/validations/i18n_validation_test.rb" "test/cases/validations/length_validation_test.rb" "test/cases/dup_test.rb" "test/cases/date_time_test.rb" "test/cases/unconnected_test.rb" "test/cases/yaml_serialization_test.rb" "test/cases/bind_parameter_test.rb" "test/cases/associations/eager_test.rb" "test/cases/associations/eager_load_includes_full_sti_class_test.rb" "test/cases/associations/has_and_belongs_t
 o_many_associations_test.rb" "test/cases/associations/left_outer_join_association_test.rb" "test/cases/associations/has_one_associations_test.rb" "test/cases/associations/bidirectional_destroy_dependencies_test.rb" "test/cases/associations/required_test.rb" "test/cases/associations/has_one_through_associations_test.rb" "test/cases/associations/extension_test.rb" "test/cases/associations/inverse_associations_test.rb" "test/cases/associations/belongs_to_associations_test.rb" "test/cases/associations/has_many_through_associations_test.rb" "test/cases/associations/has_many_associations_test.rb" "test/cases/associations/inner_join_association_test.rb" "test/cases/associations/cascaded_eager_loading_test.rb" "test/cases/associations/eager_load_nested_include_test.rb" "test/cases/associations/nested_through_associations_test.rb" "test/cases/associations/join_model_test.rb" "test/cases/associations/callbacks_test.rb" "test/cases/associations/eager_singularization_test.rb" "test/cases/tasks/
 sqlite_rake_test.rb" "test/cases/tasks/database_tasks_test.rb" "test/cases/tasks/postgresql_rake_test.rb" "test/cases/tasks/mysql_rake_test.rb" "test/cases/callbacks_test.rb" "test/cases/statement_cache_test.rb" "test/cases/quoting_test.rb" "test/cases/relation_test.rb" "test/cases/enum_test.rb" "test/cases/disconnected_test.rb" "test/cases/date_time_precision_test.rb" "test/cases/calculations_test.rb" "test/cases/schema_dumper_test.rb" "test/cases/adapters/sqlite3/statement_pool_test.rb" "test/cases/adapters/sqlite3/explain_test.rb" "test/cases/adapters/sqlite3/copy_table_test.rb" "test/cases/adapters/sqlite3/sqlite3_adapter_test.rb" "test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb" "test/cases/adapters/sqlite3/quoting_test.rb" "test/cases/adapters/sqlite3/collation_test.rb"
/home/yahonda/git/rails/activesupport/lib/active_support/core_ext/hash/keys.rb:14: warning: method redefined; discarding old transform_keys
/home/yahonda/git/rails/activesupport/lib/active_support/core_ext/hash/keys.rb:25: warning: method redefined; discarding old transform_keys!
Traceback (most recent call last):
        24: from /home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:4:in `<main>'
        23: from /home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:4:in `select'
        22: from /home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:15:in `block in <main>'
        21: from /home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:15:in `require'
        20: from /home/yahonda/git/rails/activerecord/test/cases/result_test.rb:3:in `<top (required)>'
        19: from /home/yahonda/git/rails/activerecord/test/cases/result_test.rb:3:in `require'
        18: from /home/yahonda/git/rails/activerecord/test/cases/helper.rb:13:in `<top (required)>'
        17: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:283:in `require'
        16: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:249:in `load_dependency'
        15: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:283:in `block in require'
        14: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:283:in `require'
        13: from /home/yahonda/git/rails/activerecord/test/support/connection.rb:6:in `<top (required)>'
        12: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:283:in `require'
        11: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:249:in `load_dependency'
        10: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:283:in `block in require'
         9: from /home/yahonda/git/rails/activesupport/lib/active_support/dependencies.rb:283:in `require'
         8: from /home/yahonda/git/rails/activerecord/test/models/professor.rb:5:in `<top (required)>'
         7: from /home/yahonda/git/rails/activerecord/test/models/professor.rb:6:in `<class:Professor>'
         6: from /home/yahonda/git/rails/activerecord/lib/active_record/associations.rb:1835:in `has_and_belongs_to_many'
         5: from /home/yahonda/git/rails/activesupport/lib/active_support/deprecation/instance_delegator.rb:22:in `silence'
         4: from /home/yahonda/git/rails/activesupport/lib/active_support/deprecation/reporting.rb:38:in `silence'
         3: from /home/yahonda/git/rails/activerecord/lib/active_record/associations.rb:1835:in `block in has_and_belongs_to_many'
         2: from /home/yahonda/git/rails/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb:92:in `through_model'
         1: from /home/yahonda/git/rails/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb:67:in `add_left_association'
/home/yahonda/git/rails/activerecord/lib/active_record/associations.rb:1669:in `belongs_to': unknown keywords: required, anonymous_class (ArgumentError)
rake aborted!
Command failed with status (1): [ruby -w -I"lib:test" -I"/home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib" "/home/yahonda/.rbenv/versions/2.5.0-dev_diag2/lib/ruby/gems/2.5.0/gems/rake-12.0.0/lib/rake/rake_test_loader.rb" "test/cases/result_test.rb" "test/cases/modules_test.rb" "test/cases/log_subscriber_test.rb" "test/cases/pooled_connections_test.rb" "test/cases/locking_test.rb" "test/cases/nested_attributes_with_callbacks_test.rb" "test/cases/fixtures_test.rb" "test/cases/habtm_destroy_order_test.rb" "test/cases/scoping/relation_scoping_test.rb" "test/cases/scoping/default_scoping_test.rb" "test/cases/scoping/named_scoping_test.rb" "test/cases/custom_locking_test.rb" "test/cases/timestamp_test.rb" "test/cases/connection_management_test.rb" "test/cases/finder_respond_to_test.rb" "test/cases/comment_test.rb" "test/cases/migration/compatibility_test.rb" "test/cases/migration/change_schema_test.rb" "test/cases/migration/change_table_test.rb" "test/
 cases/migration/references_index_test.rb" "test/cases/migration/create_join_table_test.rb" "test/cases/migration/references_statements_test.rb" "test/cases/migration/pending_migrations_test.rb" "test/cases/migration/logger_test.rb" "test/cases/migration/command_recorder_test.rb" "test/cases/migration/column_attributes_test.rb" "test/cases/migration/column_positioning_test.rb" "test/cases/migration/foreign_key_test.rb" "test/cases/migration/columns_test.rb" "test/cases/migration/index_test.rb" "test/cases/migration/references_foreign_key_test.rb" "test/cases/migration/rename_table_test.rb" "test/cases/clone_test.rb" "test/cases/database_statements_test.rb" "test/cases/inheritance_test.rb" "test/cases/invalid_connection_test.rb" "test/cases/attribute_set_test.rb" "test/cases/validations_test.rb" "test/cases/cache_key_test.rb" "test/cases/secure_token_test.rb" "test/cases/dirty_test.rb" "test/cases/time_precision_test.rb" "test/cases/invertible_migration_test.rb" "test/cases/date_test.
 rb" "test/cases/mixin_test.rb" "test/cases/integration_test.rb" "test/cases/connection_pool_test.rb" "test/cases/migration_test.rb" "test/cases/primary_keys_test.rb" "test/cases/schema_loading_test.rb" "test/cases/relations_test.rb" "test/cases/connection_specification/resolver_test.rb" "test/cases/persistence_test.rb" "test/cases/readonly_test.rb" "test/cases/multiple_db_test.rb" "test/cases/forbidden_attributes_protection_test.rb" "test/cases/binary_test.rb" "test/cases/attribute_methods/read_test.rb" "test/cases/migrator_test.rb" "test/cases/core_test.rb" "test/cases/type/adapter_specific_registry_test.rb" "test/cases/type/string_test.rb" "test/cases/type/unsigned_integer_test.rb" "test/cases/type/type_map_test.rb" "test/cases/type/date_time_test.rb" "test/cases/type/integer_test.rb" "test/cases/serialization_test.rb" "test/cases/defaults_test.rb" "test/cases/batches_test.rb" "test/cases/fixture_set/file_test.rb" "test/cases/attribute_methods_test.rb" "test/cases/test_fixtures_te
 st.rb" "test/cases/column_alias_test.rb" "test/cases/relation/where_test.rb" "test/cases/relation/mutation_test.rb" "test/cases/relation/record_fetch_warning_test.rb" "test/cases/relation/predicate_builder_test.rb" "test/cases/relation/delegation_test.rb" "test/cases/relation/where_chain_test.rb" "test/cases/relation/where_clause_test.rb" "test/cases/relation/or_test.rb" "test/cases/relation/merging_test.rb" "test/cases/json_attribute_test.rb" "test/cases/explain_test.rb" "test/cases/aggregations_test.rb" "test/cases/touch_later_test.rb" "test/cases/reflection_test.rb" "test/cases/collection_cache_key_test.rb" "test/cases/sanitize_test.rb" "test/cases/i18n_test.rb" "test/cases/suppressor_test.rb" "test/cases/reserved_word_test.rb" "test/cases/null_relation_test.rb" "test/cases/nested_attributes_test.rb" "test/cases/type_test.rb" "test/cases/attribute_test.rb" "test/cases/multiparameter_attributes_test.rb" "test/cases/json_serialization_test.rb" "test/cases/query_cache_test.rb" "test
 /cases/hot_compatibility_test.rb" "test/cases/explain_subscriber_test.rb" "test/cases/serialized_attribute_test.rb" "test/cases/transaction_callbacks_test.rb" "test/cases/transaction_isolation_test.rb" "test/cases/adapter_test.rb" "test/cases/coders/yaml_column_test.rb" "test/cases/coders/json_test.rb" "test/cases/attribute_decorators_test.rb" "test/cases/reload_models_test.rb" "test/cases/ar_schema_test.rb" "test/cases/reaper_test.rb" "test/cases/counter_cache_test.rb" "test/cases/column_definition_test.rb" "test/cases/attributes_test.rb" "test/cases/view_test.rb" "test/cases/transactions_test.rb" "test/cases/base_test.rb" "test/cases/types_test.rb" "test/cases/finder_test.rb" "test/cases/autosave_association_test.rb" "test/cases/associations_test.rb" "test/cases/store_test.rb" "test/cases/errors_test.rb" "test/cases/numeric_data_test.rb" "test/cases/connection_adapters/mysql_type_lookup_test.rb" "test/cases/connection_adapters/adapter_leasing_test.rb" "test/cases/connection_adapte
 rs/merge_and_resolve_default_url_config_test.rb" "test/cases/connection_adapters/schema_cache_test.rb" "test/cases/connection_adapters/type_lookup_test.rb" "test/cases/connection_adapters/connection_handler_test.rb" "test/cases/connection_adapters/connection_specification_test.rb" "test/cases/validations/uniqueness_validation_test.rb" "test/cases/validations/i18n_generate_message_validation_test.rb" "test/cases/validations/association_validation_test.rb" "test/cases/validations/absence_validation_test.rb" "test/cases/validations/presence_validation_test.rb" "test/cases/validations/i18n_validation_test.rb" "test/cases/validations/length_validation_test.rb" "test/cases/dup_test.rb" "test/cases/date_time_test.rb" "test/cases/unconnected_test.rb" "test/cases/yaml_serialization_test.rb" "test/cases/bind_parameter_test.rb" "test/cases/associations/eager_test.rb" "test/cases/associations/eager_load_includes_full_sti_class_test.rb" "test/cases/associations/has_and_belongs_to_many_associatio
 ns_test.rb" "test/cases/associations/left_outer_join_association_test.rb" "test/cases/associations/has_one_associations_test.rb" "test/cases/associations/bidirectional_destroy_dependencies_test.rb" "test/cases/associations/required_test.rb" "test/cases/associations/has_one_through_associations_test.rb" "test/cases/associations/extension_test.rb" "test/cases/associations/inverse_associations_test.rb" "test/cases/associations/belongs_to_associations_test.rb" "test/cases/associations/has_many_through_associations_test.rb" "test/cases/associations/has_many_associations_test.rb" "test/cases/associations/inner_join_association_test.rb" "test/cases/associations/cascaded_eager_loading_test.rb" "test/cases/associations/eager_load_nested_include_test.rb" "test/cases/associations/nested_through_associations_test.rb" "test/cases/associations/join_model_test.rb" "test/cases/associations/callbacks_test.rb" "test/cases/associations/eager_singularization_test.rb" "test/cases/tasks/sqlite_rake_test.
 rb" "test/cases/tasks/database_tasks_test.rb" "test/cases/tasks/postgresql_rake_test.rb" "test/cases/tasks/mysql_rake_test.rb" "test/cases/callbacks_test.rb" "test/cases/statement_cache_test.rb" "test/cases/quoting_test.rb" "test/cases/relation_test.rb" "test/cases/enum_test.rb" "test/cases/disconnected_test.rb" "test/cases/date_time_precision_test.rb" "test/cases/calculations_test.rb" "test/cases/schema_dumper_test.rb" "test/cases/adapters/sqlite3/statement_pool_test.rb" "test/cases/adapters/sqlite3/explain_test.rb" "test/cases/adapters/sqlite3/copy_table_test.rb" "test/cases/adapters/sqlite3/sqlite3_adapter_test.rb" "test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb" "test/cases/adapters/sqlite3/quoting_test.rb" "test/cases/adapters/sqlite3/collation_test.rb" ]
/home/yahonda/.rbenv/versions/2.5.0-dev_diag2/bin/bundle:23:in `load'
/home/yahonda/.rbenv/versions/2.5.0-dev_diag2/bin/bundle:23:in `<main>'
Tasks: TOP => test_sqlite3 => test:sqlite3
(See full trace by running task with --trace)
$
```

#### It does NOT reproduce with this ruby version
```
$ ruby -v
ruby 2.5.0dev (2017-08-05 diag1 59518) [x86_64-linux]
```

#### It always reproduces with this version of ruby or newer
```
$ ruby -v
ruby 2.5.0dev (2017-08-05 diag2 59519) [x86_64-linux]
```

Here `diag1` and `diag2` are test branch names to specify specific commit.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>