Have you ever tried to update a Rails app from 5.2 to 6.0, or
from 6.0 to 6.1?
If so, you might have seen this deprecation:
DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "random()". 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(). (called from ...)
Note: While this deprecation message mentions Rails 6.0 as the version where the behavior is
disallowed, that change was postponed, so the deprecation also shows in Rails 6.0. The behavior is actually disallowed
in Rails 6.1.
What does this deprecation mean exactly? In this article, I will explain that in
plain English, what issue it is trying to prevent, and how to fix the problem
if you come across it in your codebase.
Read more