Skip to content

Conversation

xronos-i-am
Copy link

Summary

The problem: Float::NAN is special value in ruby. It can't be compared with ==. Because of this dirty check failed

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", "~> 6.1"
  gem "sqlite3"
end

require "active_record"
require "minitest/autorun"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

ActiveRecord::Schema.define do
  create_table :warehouse_receipts, force: true do |t|
    t.decimal :vat_coef
  end
end

class WarehouseReceipt < ActiveRecord::Base
end

class Test < Minitest::Test
  def test_nan_dirty
    wr = WarehouseReceipt.create!(vat_coef: Float::NAN)
    wr.vat_coef = Float::NAN
    assert !wr.changed? # Expected false to be truthy.
  end
end

@rails-bot
Copy link

rails-bot bot commented Jun 10, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Jun 10, 2021
@zzak
Copy link
Member

zzak commented Jun 10, 2021

🤔 I thought I've seen a similar issue/PR recently but now I can't find it.

@xronos-i-am Is this still something you're interested in?

@rails-bot rails-bot bot removed the stale label Jun 10, 2021
@xronos-i-am
Copy link
Author

@xronos-i-am Is this still something you're interested in?

no

@zzak zzak reopened this Jun 11, 2021
@zzak
Copy link
Member

zzak commented Jun 11, 2021

@xronos-i-am I realize you may not feel like finishing this PR, but I'd like to leave it open to see if anyone else may be interested in this. At worst, @rails-bot auto-closes this PR if there is no activity after some time.

I also was wondering since I just realize this change was targeting 6-1-stable is this commit already fixed in main and you're requesting a backport? Do you have any other context on this change? 🙇

@xronos-i-am
Copy link
Author

I also was wondering since I just realize this change was targeting 6-1-stable is this commit already fixed in main and you're requesting a backport? Do you have any other context on this change?

There were too many issues with Float::NAN therefore I solve my problem in another way

@marcelolx
Copy link
Contributor

@zzak I ran the script against main and it seems that the problem still exists. I'll pick up this

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", github: "rails/rails", branch: "main"
  gem "sqlite3"
end

require "active_record"
require "minitest/autorun"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

ActiveRecord::Schema.define do
  create_table :warehouse_receipts, force: true do |t|
    t.decimal :vat_coef
  end
end

class WarehouseReceipt < ActiveRecord::Base
end

class Test < Minitest::Test
  def test_nan_dirty
    wr = WarehouseReceipt.create!(vat_coef: Float::NAN)
    wr.vat_coef = Float::NAN
    assert !wr.changed? # Expected false to be truthy.
  end
end

@marcelolx
Copy link
Contributor

@zzak I opened a PR with a test case

@byroot
Copy link
Member

byroot commented Jul 22, 2021

Closing in favor of #42831

@byroot byroot closed this Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants