Possible ActiveRecord regression since 3.0 #4409

denisj opened this Issue Jan 11, 2012 · 3 comments


None yet
3 participants

denisj commented Jan 11, 2012

I have sometime parameters like that

{ :offset => "150" }

sending after a javascript action. So when I try to create a sql query

sql_query = Blog.send(:construct_finder_arel, { :offset => "150" }).to_sql

I get

ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''150'' at line 1: SELECT  `blogs`.* FROM `blogs` LIMIT 10 OFFSET '150'

because contrary to active_record 2.3, "offset" is not transformed into Fixnum.
In lib/active_record/connection_adapters/abstract/database_statements.rb line 201

def add_limit_offset!(sql, options)
  if limit = options[:limit]
    sql << " LIMIT #{sanitize_limit(limit)}"
    if offset = options[:offset]
      sql << " OFFSET #{offset.to_i}"

In active_record 3.0, lib/active_record/relation/query_methods.rb line 183

arel = arel.skip(@offset_value) if @offset_value

This regression (if it is) seems to be in all versions since rails 3.0.


judearasu commented Jan 16, 2012

Are u not able to send parameters like without double quotes

sql_query = Blog.send(:construct_finder_arel, { :offset => 150 }).to_sql


denisj commented Jan 17, 2012

My parameters (for this action) are hidden in the page like

<input id="offset" type="hidden" value="0" name="offset">

because we need to keep them from an action to another one.
I think this is a problem because in rails 2.3, we did't need to "transform" the offset because rails did.

So I make a correction here: #4410


arunagw commented Mar 12, 2012

Closing this as a2c2f40 done here


@arunagw arunagw closed this Mar 12, 2012

This was referenced Mar 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment