Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange error coming from ActiveRecord (probably)
    text
    copied!<p>My development environment:</p> <ul> <li>Ubuntu 9</li> <li>Ruby 1.9.1/1.8.7 (rvm)</li> <li>Rails 2.3.5</li> <li>Mysql 5.0</li> <li>Apache Passenger</li> </ul> <p>Below is the part of the program flow to represent the issue.</p> <p>Request comes:</p> <pre><code>#action def create begin @report = Report.new(params[:report]) ... rescue LocationNotFound =&gt; e ... end end </code></pre> <p>Report constructor:</p> <pre><code>class Report attr_accessor :locations def initialize(params = {}) @locations = params[:locations] ? fetch_locations(params[:locations]) : [] end ... end </code></pre> <p>fetch_locations:</p> <pre><code>def fetch_locations(loc_names) Rails.logger.debug "LOC_NAMES: " + loc_names.inspect ls = Location.find(:all, :conditions =&gt; [ # line 57 "locations.name in (#{loc_names.map{'?'}.join(',')})", *loc_names ], :include =&gt; [:sample_summaries, :samples]) # loc_names will never be empty ... end </code></pre> <p>Location model:</p> <pre><code>class Location &lt; ActiveRecord::Base has_many :sample_summaries has_many :samples, :through =&gt; :sample_summaries ... end </code></pre> <p>Now, the first time (after passenger restart) this runs fine and does the job. Most of the consequent times I get the error:</p> <pre><code>Mar-11 11:01:00 #15098 DEBUG: LOC_NAMES: ["Moscow, RF", "London, UK"] Mar-11 11:01:00 #15098 DEBUG: Location Load (0.0ms) SELECT * FROM `locations` WHERE (locations.name in ('Moscow, RF','London, UK')) Mar-11 11:01:00 #15098 DEBUG: SampleSummary Load (0.0ms) SELECT `sample_summaries`.* FROM `sample_summaries` WHERE (`sample_summaries`.location_id IN (1,3)) Mar-11 11:01:00 #15098 DEBUG: SampleSummary Columns (0.0ms) SHOW FIELDS FROM `sample_summaries` Mar-11 11:01:00 #15098 FATAL: NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include?): app/models/report.rb:57:in `fetch_locations' app/models/report.rb:9:in `initialize' app/controllers/report_controller.rb:11:in `new' app/controllers/report_controller.rb:11:in `create' </code></pre> <p>Looks quite random to me. Any ideas?</p> <p>P.S. I also tried to wrap the query in <code>uncached</code> block, but that didn't change anything.</p> <p><b>EDIT</b></p> <p>Here is what SampleSummary model looks like:</p> <pre><code>class SampleSummary &lt; ActiveRecord::Base has_many :samples belongs_to :location ... #validations default_scope :include =&gt; :samples, :order =&gt; 'rss_ts desc' ... end </code></pre> <p><b>EDIT2</b></p> <p>It doesn't fail in console.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload