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 breaks code functionality for jsonb columns #1166

Open
vccoffey opened this issue Oct 25, 2023 · 2 comments
Open

Rails/WhereEquals breaks code functionality for jsonb columns #1166

vccoffey opened this issue Oct 25, 2023 · 2 comments

Comments

@vccoffey
Copy link

vccoffey commented Oct 25, 2023

When working with postgres jsonb columns, the build in rails where tools fail


Expected behavior

Given that I have a postgres jsonb column like this:

create_table "widgets", id: :serial, force: :cascade do |t|
    t.jsonb "jsonb_column_name", default: [], null: false
    ...
end

rubocop should ignore the following code
Widget.where("jsonb_column_name = ?", "[]")

Actual behavior

rubocop corrects the code to:
Widget.where(jsonb_column_name: "[]")
which returns 0 records as it is now looking for the string literal rather than an empty array

Steps to reproduce the problem

see above

RuboCop version

1.56.3 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [arm64-darwin22]
  - rubocop-rails 2.21.1
@fatkodima
Copy link
Contributor

Rubocop does not inspect column types, so you need to just use # rubocop:disable at this line.

@vccoffey
Copy link
Author

For others, RoboCop does not complain about
where("jsonb_column_name = '[]'")

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

2 participants