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

Rails/WhereEquals cop report offenses with not equivalent auto correction code for database name contained where query since 2.26.0 #1340

Closed
r-plus opened this issue Aug 26, 2024 · 0 comments · Fixed by #1341
Labels
bug Something isn't working

Comments

@r-plus
Copy link

r-plus commented Aug 26, 2024

Expected behavior

Redshift::User.where('mysql.users.status = ?', 1)

not report offenses for this code that contains where clause database_name.table_name.column_name style query.
That is rubocop-rails v2.25.1 behavior.

NOTE: This query is a query to mysql via Redshift using Redshift Federated Query.

Actual behavior

$ bundle exec rubocop test.rb
Inspecting 1 file
C

Offenses:

test.rb:1:16: C: [Correctable] Rails/WhereEquals: Use where(mysql: { users: 1 }) instead of manually constructing SQL.
Redshift::User.where('mysql.users.status = ?', 1)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

report offense with not equivalent auto correction code.

Steps to reproduce the problem

  • Create file with Redshift::User.where('mysql.users.status = ?', 1)
  • run rubocop with rubocop-rails

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:

$ be rubocop -V
1.65.1 (using Parser 3.3.4.2, rubocop-ast 1.32.1, running on ruby 3.3.4) [arm64-darwin23]
  - rubocop-capybara 2.21.0
  - rubocop-erb 0.5.3
  - rubocop-factory_bot 2.26.1
  - rubocop-graphql 1.5.4
  - rubocop-performance 1.21.1
  - rubocop-rails 2.26.0
  - rubocop-rspec 3.0.4
  - rubocop-rspec_rails 2.30.0
  - rubocop-slim 0.2.7
Earlopain added a commit to Earlopain/rubocop-rails that referenced this issue Aug 26, 2024
…qualifying the database name

And `Rails/WhereNot`/``Rails/WhereRange` as well.

I'd like to extract some of this logic to a module sometime since it is looking rather similar.

The original issue mentions Redshift, and I know that MSSQL allows cross-database queries as well
@rubocop rubocop deleted a comment Aug 26, 2024
@koic koic added the bug Something isn't working label Aug 27, 2024
koic added a commit that referenced this issue Aug 27, 2024
[Fix #1340] Fix a false positive for `Rails/WhereEquals` when qualifying the database name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants