Skip to content

Error occurred with ActiveRecord::ModelSchema::ClassMethods#ignored_columns= #1247

Closed
@obregonia1

Description

Thank you for always letting me use RuboCop. I am reporting that I encountered an error while working on deleting a column in a Rails app. I would be happy if you could handle this problem.

https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-ignored_columns-3D


Expected behavior

No errors.

Actual behavior

$ rubocop -d app/models/foo.rb                     
For /rails/site: configuration from /rails/site/.rubocop.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/config/default.yml
Default configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.20.0/config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.20.0/lib/../config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-factory_bot-2.25.1/config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-factory_bot-2.25.1/lib/../config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/config/default.yml
configuration from /rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-graphql-1.5.0/config/default.yml
configuration from #{path}
Inheriting configuration from /rails/site/.rubocop_todo.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /rails/site/app/models/foo.rb
An error occurred while Rails/UnusedIgnoredColumns cop was inspecting /rails/site/app/models/foo.rb:4:2.
undefined method `type' for nil:NilClass
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/rails/schema_loader/schema.rb:47:in `each_table'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/rails/schema_loader/schema.rb:34:in `build!'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/rails/schema_loader/schema.rb:14:in `initialize'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/rails/schema_loader.rb:46:in `new'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/rails/schema_loader.rb:46:in `load!'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/rails/schema_loader.rb:18:in `load'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/cop/mixin/active_record_helper.rb:42:in `schema'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/cop/rails/unused_ignored_columns.rb:41:in `on_send'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:105:in `each'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:69:in `on_op_asgn'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:154:in `on_class'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/team.rb:98:in `investigate'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:345:in `block in inspect_file'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:344:in `each'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:344:in `flat_map'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:344:in `inspect_file'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:314:in `loop'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:164:in `block in file_offenses'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:189:in `file_offense_cache'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:163:in `file_offenses'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:154:in `process_file'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:134:in `each'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:134:in `reduce'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:134:in `each_inspected_file'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:120:in `inspect_files'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/runner.rb:73:in `run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli/command.rb:11:in `run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli/environment.rb:18:in `run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli.rb:118:in `run_command'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli.rb:125:in `execute_runners'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli.rb:51:in `block in run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli.rb:77:in `profile_if_needed'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cli.rb:43:in `run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/exe/rubocop:19:in `block in <top (required)>'
/usr/local/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/rails/site/vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/exe/rubocop:19:in `<top (required)>'
/rails/site/vendor/bundle/ruby/3.2.0/bin/rubocop:25:in `load'
/rails/site/vendor/bundle/ruby/3.2.0/bin/rubocop:25:in `<top (required)>'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/cli/exec.rb:58:in `load'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/cli/exec.rb:58:in `kernel_load'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/cli/exec.rb:23:in `run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/cli.rb:486:in `exec'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/cli.rb:31:in `dispatch'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/cli.rb:25:in `start'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/exe/bundle:48:in `block in <top (required)>'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/lib/bundler/friendly_errors.rb:120:in `with_friendly_errors'
/rails/site/vendor/bundle/ruby/3.2.0/gems/bundler-2.3.26/exe/bundle:36:in `<top (required)>'
/usr/local/bundle/bin/bundle:25:in `load'
/usr/local/bundle/bin/bundle:25:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/UnusedIgnoredColumns cop was inspecting /rails/site/app/models/foo.rb:4:2.
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.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.2.2) [aarch64-linux-musl]
Finished in 0.42401237500598654 seconds

Steps to reproduce the problem

foo.rb

# frozen_string_literal: true

class Foo < ApplicationRecord
  self.ignored_columns += [:bar]
end

And then, execute rubocop.

RuboCop version

$ [bundle exec] rubocop -V
1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.2.2) [aarch64-linux-musl]
  - rubocop-factory_bot 2.25.1
  - rubocop-graphql 1.5.0
  - rubocop-rails 2.23.1
  - rubocop-rspec 2.26.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions