Mark safe SQL with Arel.sql
Rails 5.2 is raising a warning in some places: DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s). Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). IMHO this warning is simply wrong, since we're using known PostgreSQL functions like LOWER() or RANDOM(). AFAIK this code works without warnings in Rails 6.0 [1][2] However, since the warning is annoying, we need to take measures so our logs are clean. [1] https://github.com/rails/rails/commit/6c82b6c99d [2] https://github.com/rails/rails/commit/64d8c54e16
This commit is contained in:
@@ -49,7 +49,7 @@ class Comment < ApplicationRecord
|
||||
|
||||
scope :sort_by_most_voted, -> { order(confidence_score: :desc, created_at: :desc) }
|
||||
scope :sort_descendants_by_most_voted, -> { order(confidence_score: :desc, created_at: :asc) }
|
||||
scope :sort_by_supports, -> { order("cached_votes_up - cached_votes_down DESC") }
|
||||
scope :sort_by_supports, -> { order(Arel.sql("cached_votes_up - cached_votes_down DESC")) }
|
||||
|
||||
scope :sort_by_newest, -> { order(created_at: :desc) }
|
||||
scope :sort_descendants_by_newest, -> { order(created_at: :desc) }
|
||||
|
||||
Reference in New Issue
Block a user