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

An error occurred while Rails/UniqueValidationWithoutIndex cop #216

Closed
jamesst20 opened this issue Mar 25, 2020 · 11 comments
Closed

An error occurred while Rails/UniqueValidationWithoutIndex cop #216

jamesst20 opened this issue Mar 25, 2020 · 11 comments

Comments

@jamesst20
Copy link

jamesst20 commented Mar 25, 2020

Information

0.80.1 (using Parser 2.7.0.5, running on ruby 2.6.3 x86_64-linux)

(Running under BitBucket-Pipeline in Ruby 2.6.3 docker image)

Edit April 1, 2020
Error is still present:

rubocop-rails 2.5.0
Mention the following information in the issue report:
0.81.0 (using Parser 2.7.0.5, running on ruby 2.6.3 x86_64-linux)

Error

An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /opt/atlassian/pipelines/agent/build/app/models/user.rb:11:2.
To see the complete backtrace run rubocop -d.
1 error occurred:
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /opt/atlassian/pipelines/agent/build/app/models/user.rb:11:2.
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.80.1 (using Parser 2.7.0.5, running on ruby 2.6.3 x86_64-linux)
Inspecting 56 files
........................................................
56 files inspected, no offenses detected

The file in error

# User of the app
class User < ApplicationRecord
  attr_writer :login # Used for devise authentication by username

  devise :invitable, :database_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :lockable, :timeoutable, timeout_in: 2.days

  belongs_to :legacy_user, foreign_key: :id, inverse_of: :user

  validates :username, presence: true, uniqueness: { case_sensitive: false }
  validates :username, format: { with: /^[a-zA-Z0-9_\.]*$/, multiline: true }

  def login
    @login || username
  end

  def self.find_first_by_auth_conditions(warden_conditions)
    conditions = warden_conditions.dup
    login = conditions.delete(:login)
    if login.present?
      where(conditions).find_by(["lower(username) = :value ", { value: login.downcase }])
    elsif conditions[:username].nil?
      find_by(conditions)
    else
      find_by(username: conditions[:username])
    end
  end
end

Extra information

I am not able to replicate the issue on my PC (Mac OS Catalina).

Thank you

@denny
Copy link

denny commented Mar 25, 2020

I might have a bizarre extra clue or two to add to this:

denny/ShinyCMS-ruby@b2856c1

denny/ShinyCMS-ruby@a0c1a2a

@koic koic transferred this issue from rubocop/rubocop Mar 26, 2020
@koic
Copy link
Member

koic commented Mar 26, 2020

@jamesst20 Thank you for the feedback. Can you show me the backtrace of running rubocop -d?

@jamesst20
Copy link
Author

@koic

BitBucket Pipeline didn't make it easy to copy paste hehe

https://pastebin.com/LQhyhHY3

@sagg0t
Copy link

sagg0t commented Apr 1, 2020

@koic

Have same issue
0.74.0 (using Parser 2.7.0.5, running on ruby 2.6.5 x86_64-linux)

Running with debug flag gives this error:

An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /home/oleh/dev/bookstore/app/models/category.rb:4:2.
undefined method `method?' for #<RuboCop::AST::BlockNode:0x0000558992abdbe8>
Did you mean?  method
               methods

@koic
Copy link
Member

koic commented Apr 1, 2020

@olehvolynets Can you open a new issue with the error reproduction steps?
https://github.com/rubocop-hq/rubocop-rails/issues/new?template=bug_report.md

@sagg0t
Copy link

sagg0t commented Apr 1, 2020

@koic Sorry, couldn't reproduce the error, but noticed that rubocop was outdated, so updating to 0.81.0 and rubocop-rails to 2.5 solved that error for me.
Previously had rubocop 0.74.0 and rubocop-rails 2.3.
But now have bug described in #225

@jamesst20
Copy link
Author

I updated rubocop and still having the same error

Mention the following information in the issue report:
0.81.0 (using Parser 2.7.0.5, running on ruby 2.6.3 x86_64-linux)

@sagg0t
Copy link

sagg0t commented Apr 1, 2020

@jamesst20 is rubocop-rails version 2.5 ?

@jamesst20
Copy link
Author

@olehvolynets Yes it is

@koic
Copy link
Member

koic commented Apr 2, 2020

RuboCop Rails 2.5.1 has been released. If the error is the same cause as #214, the issue will be resolved.
https://github.com/rubocop-hq/rubocop-rails/releases/tag/v2.5.1

If you upgrade to RuboCop Rails 2.5.1 and still get unexpected errors, please open a new issue with reproduction steps . Thank you for your feedback!

@koic koic closed this as completed Apr 2, 2020
@jamesst20
Copy link
Author

#226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants