You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading from 2.11.3 to 2.12.0 I'm getting an "An error occurred while Rails/HasManyOrHasOneDependent cop was inspecting" when inspecting files that have a :has_many with a lambda in.
An example of the code that is now throwing an error is:
rubocop -A -d app/models/user.rb
For /Users/stu/ruby_thing/: configuration from /Users/stu/ruby_thing/.rubocop.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-faker-1.1.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-faker-1.1.0/config/default.yml
Default configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.15.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.15.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rails-2.12.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rails-2.12.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rspec-2.4.0/config/default.yml
configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rspec-2.4.0/config/default.yml
Inheriting configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ruby_style_guide-8.3.4/default.yml
Inheriting configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ruby_style_guide-8.3.4/rails.yml
Inheriting configuration from /Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ruby_style_guide-8.3.4/rspec.yml
Inheriting configuration from /Users/stu/ruby_thing/.rubocop_todo.yml
Inspecting 1 file
Scanning /Users/stu/ruby_thing/app/models/user.rb
An error occurred while Rails/HasManyOrHasOneDependent cop was inspecting /Users/stu/ruby_thing/app/models/user.rb:25:4.
undefined method `first' for nil:NilClass/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rails-2.12.0/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:117:in `valid_options?'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-rails-2.12.0/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:80:in `on_send'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:154:in `on_class'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:138:in `on_while'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_module'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:20:in `walk'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cop/team.rb:83:in `investigate'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:310:in `inspect_file'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:254:in `block in do_inspection_loop'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:288:in `block in iterate_until_no_changes'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:281:in `loop'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:130:in `block in file_offenses'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:155:in `file_offense_cache'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:129:in `file_offenses'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:120:in `process_file'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:100:in `each'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:100:in `reduce'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:86:in `inspect_files'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:47:in `run'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli/command.rb:11:in `run'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli.rb:71:in `run_command'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli.rb:78:in `execute_runners'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/lib/rubocop/cli.rb:47:in `run'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/exe/rubocop:12:in `block in <top (required)>'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/rubocop-1.20.0/exe/rubocop:12:in `<top (required)>'/Users/stu/.rbenv/versions/3.0.2/bin/rubocop:23:in `load'/Users/stu/.rbenv/versions/3.0.2/bin/rubocop:23:in `<top (required)>'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/cli.rb:474:in `exec'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/cli.rb:30:in `dispatch'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/cli.rb:24:in `start'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/libexec/bundle:49:in `block in<top (required)>'/Users/stu/.rbenv/versions/3.0.2/lib/ruby/3.0.0/bundler/friendly_errors.rb:128:in `with_friendly_errors'
/Users/stu/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/libexec/bundle:37:in `<top (required)>'/Users/stu/.rbenv/versions/3.0.2/bin/bundle:23:in `load'/Users/stu/.rbenv/versions/3.0.2/bin/bundle:23:in `<main>'.1 file inspected, no offenses detected1 error occurred:An error occurred while Rails/HasManyOrHasOneDependent cop was inspecting /Users/stu/ruby_thing/app/models/user.rb:25:4.Errors are usually caused by RuboCop bugs.Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.20.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 3.0.2 x86_64-darwin20)
Finished in 0.7643180000013672 seconds
Steps to reproduce the problem
Create a model with a :has_many that uses a lambda (like the example above)
Run rubocop on the file
RuboCop version
Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:
After upgrading from
2.11.3
to2.12.0
I'm getting an "An error occurred while Rails/HasManyOrHasOneDependent cop was inspecting" when inspecting files that have a:has_many
with a lambda in.An example of the code that is now throwing an error is:
Expected behavior
Inspecting the code doesn't throw an error.
Actual behavior
Steps to reproduce the problem
:has_many
that uses a lambda (like the example above)rubocop
on the fileRuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:
The text was updated successfully, but these errors were encountered: