Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As of ActiveRecord 3.2.9, NaN no longer supported; throws FloatDomainError (NaN) #17

Closed
trisweb opened this issue Jan 4, 2013 · 2 comments

Comments

@trisweb
Copy link

trisweb commented Jan 4, 2013

See the change here:

rails/rails@v3.2.8...v3.2.10#L63L78

This causes ActiveRecord to fail on NaN input with the error "FloatDomainError (NaN)"

Here's the full stack of this error from an older version fork we're using at harleyttd/rubyamf—I did a quick look through the current code and it appears this will still be an issue in the current model.rb, so I'm still reporting it for good measure.

/Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/connection_adapters/column.rb:178:in `to_i'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/connection_adapters/column.rb:178:in `value_to_integer'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/connection_adapters/column.rb:78:in `type_cast'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_methods/dirty.rb:86:in `_field_changed?'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_methods/dirty.rb:63:in `write_attribute'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_methods/write.rb:14:in `slider_min_old='
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:78:in `each'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:36:in `attributes='
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/rails/model.rb:105:in `rubyamf_init'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/class_mapping.rb:201:in `populate_ruby_obj'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/request_parser.rb:43:in `populate_from_stream'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/request_parser.rb:43:in `handle_amf'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/request_parser.rb:30:in `call'
#... etc.

This is a fairly large issue since Flash uses NaN extensively as an uninitialized Number value (as far as I can remember) and it's very likely that that will make it to ActiveRecord.

Interesting to note that previously Rails handled NaN incorrectly by instead assuming it was a Boolean in value.to_i rescue value ? 1 : 0 to convert it to an int (see line in diff above). This means (yikes) that NaN was interpreted as the number 1, since NaN is a true value in ruby, unless there was some workaround already in place that I'm not aware of.

Cross-posting this to rails/rails to let them decide if they will fix it by correctly handling NaN in ActiveRecord.

@trisweb
Copy link
Author

trisweb commented Jan 4, 2013

Actually scratch that part about NaN being interpreted as 1... that was fixed in rails/rails@13823a4c

@trisweb
Copy link
Author

trisweb commented Jan 4, 2013

This should have been fixed by this commit in rails: rails/rails@8d98c83b

But it was not, since NaN.to_i exists and throws an exception.

Opening an issue over there...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants