Note that there are some explanatory texts on larger screens.

plurals
  1. POSunspot .index: FloatDomainError: Infinity
    primarykey
    data
    text
    <p>I have a large database of products (>23.000), and when I made a change to my schema.xml or in the search definitions of sunspot, I want to re-index all products. But sometimes the re-index fails with the following error:</p> <pre><code>FloatDomainError: Infinity from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/type.rb:142:in `to_i' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/type.rb:142:in `to_indexed' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/field.rb:44:in `to_indexed' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/field_factory.rb:59:in `populate_document' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:100:in `block in prepare' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:99:in `each' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:99:in `prepare' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:26:in `block in add' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:26:in `map' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:26:in `add' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/session.rb:91:in `index' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot.rb:184:in `index' from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.8.168/lib/new_relic/agent/method_tracer.rb:508:in `block in index_with_trace_SolrClient_Sunspot_index' from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.8.168/lib/new_relic/agent/method_tracer.rb:259:in `trace_execution_scoped' from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.8.168/lib/new_relic/agent/method_tracer.rb:503:in `index_with_trace_SolrClient_Sunspot_index' from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot_rails/lib/sunspot/rails/searchable.rb:401:in `solr_index' from (irb):4:in `block in irb_binding' from (irb):4:in `each' from (irb):4 from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start' from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start' from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:41:in `&lt;top (required)&gt;' from script/rails:6:in `require' from script/rails:6:in `&lt;main&gt;'irb(main):005:0&gt; </code></pre> <p>I debugged into the re-index, and caught the product that is throwing that error. But then, when I try to call the <code>.index</code> method on that product, everything works fine.</p> <p>I've read about this <code>FloatDomainError: Infinity</code> that this happens, when a certain number datatype that supports <code>INFINITY</code> is converted to a number datatype, that doesn't support <code>INFINITY</code>. The problem is, that I can't figure out, where to start debugging, or what exactly causes this error.</p> <p><strong>EDIT</strong></p> <p>I submitted an issue to the github repo: <a href="https://github.com/sunspot/sunspot/issues/521" rel="nofollow">https://github.com/sunspot/sunspot/issues/521</a></p> <p>Because it's easier, I add the information from github here as well:</p> <p>This is my search definition for the <code>count_on_hand</code> field (that field which throws the error):</p> <pre><code>integer :count_on_hand, stored: true do |product| product.on_hand.nil? ? -1 : product.on_hand end </code></pre> <p>I don't think that the <code>schema.xml</code> field definitions are helpful, because they only contain the standard configuration.</p> <p>Then, I debugged into the <code>populate_document</code> method at <code>field_factory.rb:57</code> inside the sunspot gem, and added some more output when the error is thrown:</p> <pre><code>model.inspect =&gt; #&lt;Spree::Product id: 19502, name: "Foo Bar", description: "Bar foo", available_on: "2013-12-14 13:30:10", deleted_at: nil, permalink: "foo-bar", meta_description: nil, meta_keywords: "", tax_category_id: 3, shipping_category_id: 1, created_at: "2013-11-26 15:12:25", updated_at: "2013-12-14 13:30:10", count_on_hand: 2&gt; document.inspect =&gt; #&lt;RSolr::Xml::Document:0x007ff6f4d58390 @fields=[#&lt;RSolr::Xml::Field:0x007ff6f4d58570 @attrs={:name=&gt;:id}, @value="Spree::Product 19502"&gt;, &lt;RSolr::Xml::Field:0x007ff6f4d58b88 @attrs={:name=&gt;:type}, @value="Spree::Product"&gt;, &lt;RSolr::Xml::Field:0x007ff6f4d58e30 @attrs={:name=&gt;:type}, @value="ActiveRecord::Base"&gt;, &lt;RSolr::Xml::Field:0x007ff6f49a3268 @attrs={:name=&gt;:class_name}, @value="Spree::Product"&gt;, &lt;RSolr::Xml::Field:0x007ff6f47b95b0 @attrs={:name=&gt;:available_on_d}, @value="2013-12-14T13:30:10Z"&gt;, &lt;RSolr::Xml::Field:0x007ff6f47a7220 @attrs={:name=&gt;:price_f}, @value="10.3"&gt;], @attrs={:boost=&gt;1.0}&gt; @field =&gt; #&lt;Sunspot::AttributeField:0x00000006081320 @multiple=false, @type=#&lt;Sunspot::Type::IntegerType:0x00000003722dd0&gt;, @name=:count_on_hand, @stored=true, @more_like_this=false, @indexed_name="count_on_hand_is", @reference=nil&gt; value =&gt; Infinity </code></pre> <p>As you can see, the <code>count_on_hand</code> from <code>model.inspect</code> has the value <code>2</code>. But the <code>value</code> variable inside the method has the value <code>Infinity</code>. Furthermore, the <code>count_on_hand</code> doesn't show up in the <code>document.inspect</code>. I'm not sure, if this has something to do with it, but maybe it's a hint.</p> <p>The problem is, that I can't reproduce this issue in development. That error above was thrown in production, and that's the reason why I monkey-patched the sunspot gem, and added this code into production (along with an Airbrake.notify):</p> <pre><code>module Sunspot module FieldFactory class Static &lt; Abstract alias_method :old_populate_document, :populate_document def populate_document(document, model) begin value = @data_extractor.value_for(model) old_populate_document(document, model) rescue Exception =&gt; e message = $!.inspect model_msg = model.inspect document_msg = document.inspect field_msg = @field.inspect debugger Airbrake.notify(e, :error_message =&gt; "Sunspot populate_document crashed with: #{message} ___________________ model: #{model_msg} ___________________ document: #{document_msg} ___________________ field: #{field_msg} ___________________ value: #{value}", :environment_name =&gt; "production" ) raise(e) end end end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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