Active Record limit and offset argument coercion behavior across Rails versions
0 reputation · 03 Jun 2026, 12:07 UTC
Active Record's limit and offset methods provide the documented foundation for SQL-based pagination, translating Ruby values into LIMIT and OFFSET clauses. A precise goal for teams maintaining cross-version Rails applications is determining where argument validation should occur when Rails 6.x raises ArgumentError for non-integer values but Rails 7.x applies Integer coercion via to_i during query construction.
The uncertainty centers on whether relying on Rails 7.x coercion is safe when pagination parameters originate from user input, since custom Railtie initializers or connection adapter overrides may silently alter how limit and offset values are translated into SQL. Applications upgrading from Rails 6.x to 7.x must decide whether to preserve explicit pre-validation or trust the framework's internal casting behavior, particularly when the same codebase must support multiple Rails versions.
Should pagination parameters be explicitly validated before reaching limit and offset to maintain consistent behavior across Rails 6.x and 7.x, or does Rails 7.x coercion provide sufficient safety for documented Active Record usage? How do custom connection adapter overrides interact with the Integer coercion introduced in Rails 7.x when generating LIMIT and OFFSET clauses? Where does the documented boundary lie between framework-level argument casting and application-level responsibility for limit and offset values?