Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 2.8.0 with Rails/UniqueValidationWithoutIndex cop? #360

Closed
eneagoe opened this issue Sep 15, 2020 · 2 comments
Closed

Regression in 2.8.0 with Rails/UniqueValidationWithoutIndex cop? #360

eneagoe opened this issue Sep 15, 2020 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@eneagoe
Copy link

eneagoe commented Sep 15, 2020

Is it possible that 2.8.0 introduced a regression?

We have a class which passes the checks on 2.7.1, but with 2.8.0 it fails:

Scanning [...]/app/models/committees/committee_member_role.rb
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting [...]app/models/committees/committee_member_role.rb:59:4.
undefined method `with_column?' for nil:NilClass
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-rails-2.8.0/lib/rubocop/cop/mixin/active_record_helper.rb:55:in `resolve_relation_into_column'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-rails-2.8.0/lib/rubocop/cop/rails/unique_validation_without_index.rb:84:in `block in column_names'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-rails-2.8.0/lib/rubocop/cop/rails/unique_validation_without_index.rb:82:in `map!'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-rails-2.8.0/lib/rubocop/cop/rails/unique_validation_without_index.rb:82:in `column_names'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-rails-2.8.0/lib/rubocop/cop/rails/unique_validation_without_index.rb:50:in `find_schema_information'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-rails-2.8.0/lib/rubocop/cop/rails/unique_validation_without_index.rb:38:in `on_send'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:99:in `block (2 levels) in trigger_responding_cops'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:152:in `with_cop_error_handling'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:98:in `block in trigger_responding_cops'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:97:in `each'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:97:in `trigger_responding_cops'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:59:in `block in on_begin'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:59:in `each'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:59:in `on_begin'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:72:in `on_begin'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:101:in `on_class'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:72:in `on_class'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:159:in `on_while'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:72:in `on_module'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:14:in `walk'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:85:in `investigate'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/team.rb:152:in `investigate_partial'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:311:in `inspect_file'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:255:in `block in do_inspection_loop'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:289:in `block in iterate_until_no_changes'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:282:in `loop'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:282:in `iterate_until_no_changes'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:251:in `do_inspection_loop'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:128:in `block in file_offenses'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:153:in `file_offense_cache'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:127:in `file_offenses'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:118:in `process_file'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:97:in `block in each_inspected_file'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:96:in `each'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:96:in `reduce'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:96:in `each_inspected_file'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:82:in `inspect_files'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/runner.rb:43:in `run'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/lib/rubocop/cli.rb:41:in `run'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/exe/rubocop:13:in `block in <top (required)>'
/Users/eneagoe/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/gems/rubocop-0.91.0/exe/rubocop:12:in `<top (required)>'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/bin/rubocop:23:in `load'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/bin/rubocop:23:in `<main>'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/bin/ruby_executable_hooks:24:in `eval'
/Users/eneagoe/.rvm/gems/ruby-2.7.1@corpware-webapp/bin/ruby_executable_hooks:24:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting [...]app/models/committees/committee_member_role.rb:59:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.91.0 (using Parser 2.7.1.4, rubocop-ast 0.4.0, running on ruby 2.7.1 x86_64-darwin19)

The relevant code for the checked class is:

module Committees
  class CommitteeMemberRole < ApplicationRecord
     validates :name, uniqueness: {scope: [:customer_id, :committee],
                                 message: proc { |_, attributes| I18n.t("has_already_been_taken", name: attributes[:value]) }}

  end
end

If we add self.table_name = "committee_member_roles" to the class definition, there's no error, but this seems a bit redundant.

Originally posted by @eneagoe in #318 (comment)

@koic koic added the duplicate This issue or pull request already exists label Sep 15, 2020
@koic
Copy link
Member

koic commented Sep 15, 2020

Dup with #348. Can you upgrade to the latest RuboCop Rails 2.8.1? Thank you.

@koic koic closed this as completed Sep 15, 2020
@eneagoe
Copy link
Author

eneagoe commented Sep 15, 2020

2.8.1 seems to have solved the problem indeed, good work.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants