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

Fix error raised when assigning NaN to an integer column #8781

Merged
merged 1 commit into from Jan 6, 2013
Merged

Fix error raised when assigning NaN to an integer column #8781

merged 1 commit into from Jan 6, 2013

Conversation

trisweb
Copy link
Contributor

@trisweb trisweb commented Jan 6, 2013

This makes integer casting cover any non-castable case by returning nil, which is in-line with the intention of the former implementation in 3525a9b, but covers the odd cases which respond to to_i but raise an error when it's called, such as NaN, Infinity and -Infinity.

Those are the only ones I know of, but it's possible other objects could raise errors on to_i, which is the reason for the generic rescue. (Note that this generic rescue was also the behavior pre-3.2.8, except that the value was interpreted as a boolean instead—fixed in 96a13fc—after this pull it will be more correctly and consistently interpreted as nil).

Fixes #8757 (see that issue for full description)

@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##

* Fix FloatDomainError when setting integer column to NaN, or anything that
responds to to_i but raises an exception on calling it. Fixes #8757.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd amend the issue number and you name in the changelog entry for the previous fix, since it was not released yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, excellent. I'll amend the commit.

@rafaelfranca
Copy link
Member

Very good. Just a minor comment.

Also covers any non-castable case by returning nil, which
is in-line with the intention of the former implementation,
but covers the odd cases which respond to to_i but raise
an error when it's called, such as NaN, Infinity and -Infinity.

Fixes #8757
@trisweb
Copy link
Contributor Author

trisweb commented Jan 6, 2013

All set. @rafaelfranca thanks for the review and advice on the little issue.

rafaelfranca added a commit that referenced this pull request Jan 6, 2013
…_error_fix

Fix error raised when assigning NaN to an integer column
@rafaelfranca rafaelfranca merged commit 9ee65aa into rails:master Jan 6, 2013
@rafaelfranca
Copy link
Member

@trisweb Thank YOU for the report and fix.

rafaelfranca pushed a commit that referenced this pull request Jan 6, 2013
Also covers any non-castable case by returning nil, which
is in-line with the intention of the former implementation,
but covers the odd cases which respond to to_i but raise
an error when it's called, such as NaN, Infinity and -Infinity.

Fixes #8757

Backport of #8781

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/column_test.rb
@trisweb trisweb deleted the tristan_8757_integer_column_nan_error_fix branch January 7, 2013 01:38
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

Successfully merging this pull request may close these issues.

Setting integer column to NaN throws FloatDomainError (NaN)
3 participants