-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
BUG: An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting <file> (uniqueness: in validation) #318
Comments
@koic any chance you've had time to look at this? Thanks in advance! I know OSS is tough and I appreciate any insight you can give! |
Thank you for opening the issue. It may take some time because I have not yet been able to reproduce the issue locally. |
@koic no problem! I fully understand that one. Its busy on my end, too. I'll try to poke at it more on my end, could always be user error! |
@rylanb Looks like there's a problem with rubocop/rubocop-rails versions. It's not in the release notes for rubocop/rubocop@a2b67db#diff-dca43f66b47f1f1c06c2c5e987d12b30R12 |
@AndrewHYi bless you 🙏 I hadn't realized I'd set a hard version w/ For anyone coming along that may see this I had
so Fix and then Fixed |
Is it possible that We have a class which passes the checks on
The relevant code for the checked class is:
If we add |
@eneagoe Please open a new issue for this. |
Version 2.20.1 introduced a regression on this. Should we follow here since is a regression or do i open a new issue? |
RuboCop Rails 2.20.2 has just been released now. Can you upgrade to the latest version? |
Sure. Let me try! |
Problem solved! Thanks a bunch! ❤️ 💚 💙 💜 💛 🧡 |
Information
I think this is a bug, but I'm not 100% sure on that. Instead of getting a 'todo fix' for the Rubocop run, the run 'passes' and tells me that it passed but Rubocop errorred. It fails on Github Actions, however.
Similar issue: #226 perhaps?
I'm happy to provide any more information that would be useful here. I'll also go back and poke at adding the indexes again, maybe I messed something up in my first try there.
Expected behavior
Rubocop tells me that there is a unique ActiveRecord validation / schema.rb mismatch on indexes and I need to add a unique index based on a scoped ActiveRecord validation.
I believe this might be related to
uniqueness: { case_sensitive: false }
oruniqueness: { scope: :state_id, case_sensitive: false }
validations in AR.Actual behavior
I get the following output during a full
bundle exec rubocop
run:Every model that is failing (I get 12 total) have some use of
uniqueness:
as their common trait.Examples:
validates :email, presence: true, uniqueness: true
validates :short_name, uniqueness: { case_sensitive: false }, presence: true
validates :email, uniqueness: true
validates :name, uniqueness: true
validates :carrier_id, uniqueness: { scope: :user_id }
validates :quote_person, presence: true, uniqueness: { message: 'already has a spouse' }
Output running -d command:
rubocop -d app/models/county.rb
https://gist.github.com/rylanb/a7fc2786018ba736c8b15837f1a03950
Steps to reproduce the problem
county.rb
Relevant schema.rb
( I think the index
index_counties_on_state_id
needs updating, but if I update to add one, it doesn't seem to change the error)Edit: I tried by adding this unique index to Counties:
So, either its the case sensitivity in there or something around the
scope: { }
or thecase_sensitive
in the scope block.bundle exec rubocop -d app/models/county.rb
:state.rb
Relevant schema.rb
RuboCop version
.rubocop.yml
The text was updated successfully, but these errors were encountered: