kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

ruby 2.4.0rc1 : ArgumentError: invalid value for BigDecimal(): #143

Closed yahonda closed 7 years ago

yahonda commented 7 years ago

This issue has been opened as https://github.com/rsim/oracle-enhanced/issues/1085 and found it also reproduces ruby-oci8 ifself.

OPatch succeeded. $


* Steps to reproduce:
ruby -w setup.rb setup
make[1]: Entering directory '/home/yahonda/git/ruby-oci8/ext/oci8'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/yahonda/git/ruby-oci8/ext/oci8'
ruby -w setup.rb test
Run options: --seed 4273

# Running:

...............................E...............F................................................................E.......................E...EE...................................

Finished in 51.762307s, 3.4195 runs/s, 259.8223 assertions/s.

  1) Error:
TestMetadata#test_sequence:
ArgumentError: invalid value for BigDecimal(): "1.E+01"
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `BigDecimal'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `to_d'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `get'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `get_data'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `block in fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `collect'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:154:in `fetch'
    /home/yahonda/git/ruby-oci8/lib/oci8/oci8.rb:314:in `select_one'
    /home/yahonda/git/ruby-oci8/test/test_metadata.rb:2482:in `assert_sequence'
    /home/yahonda/git/ruby-oci8/test/test_metadata.rb:2523:in `test_sequence'

  2) Failure:
TestOraNumber#test_cmp [/home/yahonda/git/ruby-oci8/test/test_oranumber.rb:423]:
Expected: -1
  Actual: nil

  3) Error:
TestObj1#test_select1:
ArgumentError: invalid value for BigDecimal(): "6.E+00"
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `BigDecimal'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `to_d'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `get'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `get_data'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `block in fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `collect'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:149:in `fetch'
    /home/yahonda/git/ruby-oci8/lib/oci8/oci8.rb:280:in `exec_internal'
    /home/yahonda/git/ruby-oci8/lib/oci8/oci8.rb:267:in `exec'
    /home/yahonda/git/ruby-oci8/test/test_object.rb:267:in `test_select1'

  4) Error:
TestOCI8#test_last_error:
ArgumentError: invalid value for BigDecimal(): "1.E+00"
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `BigDecimal'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `to_d'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `get'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `get_data'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `block in fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `collect'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:154:in `fetch'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:460:in `test_last_error'

  5) Error:
TestOCI8#test_cursor_in_result_set:
ArgumentError: invalid value for BigDecimal(): "2.E+00"
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `BigDecimal'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `to_d'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `get'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `get_data'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:547:in `block in fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `collect'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:546:in `fetch_one_row_as_array'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:154:in `fetch'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:263:in `block (2 levels) in test_cursor_in_result_set'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:262:in `upto'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:262:in `block in test_cursor_in_result_set'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:258:in `upto'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:258:in `test_cursor_in_result_set'

  6) Error:
TestOCI8#test_bind_number_with_implicit_conversions:
ArgumentError: invalid value for BigDecimal(): "1.E+00"
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `BigDecimal'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `to_d'
    /home/yahonda/git/ruby-oci8/lib/oci8/bindtype.rb:35:in `get'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:205:in `get_data'
    /home/yahonda/git/ruby-oci8/lib/oci8/cursor.rb:205:in `[]'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:426:in `block in test_bind_number_with_implicit_conversions'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:423:in `each'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:423:in `each_with_index'
    /home/yahonda/git/ruby-oci8/test/test_oci8.rb:423:in `test_bind_number_with_implicit_conversions'

177 runs, 13449 assertions, 1 failures, 5 errors, 0 skips
Makefile:13: recipe for target 'check' failed

It does not reproduce with ruby 2.4.0preview3

$ ruby -v
ruby 2.4.0preview3 (2016-11-07 trunk 56661) [x86_64-linux]
$ make check
...
177 runs, 13699 assertions, 0 failures, 0 errors, 0 skips
yahonda commented 7 years ago

I'm not familiar with Ruby development itself then these errors "may" be related with these "ArgumentError: invalid value for BigDecimal():"

https://bugs.ruby-lang.org/issues/10286 https://bugs.ruby-lang.org/issues/12718

koic commented 7 years ago

I'm asking questions about this change. https://github.com/ruby/bigdecimal/issues/47

koic commented 7 years ago

I've got an answer to the above. This behavior is a new specification since Ruby 2.4.0.

And I opened PR to solve this Issue. https://github.com/kubo/ruby-oci8/pull/144

Thanks.

kubo commented 7 years ago

@yahonda Thank you for the report. I merged @koic's PR.

rebase-master commented 5 years ago

This is still an issue with Ruby 2.4.1 and Rails 4.2.8. Attempted fixing with gem 'bigdecimal', '>=1.3.5' but in vain.

rebase-master commented 5 years ago

I fixed this by applying a patch:

module DecimalCastRescueRuby24
  def cast_value(value)
    if value.is_a?(::String)
      begin
        super(value)
      rescue ArgumentError
        BigDecimal(0)
      end
    else
      super(value)
    end
  end
end

ActiveRecord::Type::Decimal.prepend DecimalCastRescueRuby24
contentfree commented 5 years ago

@steady-daddy I think you're missing the first line of your patch. Probably module DecimalCastRescueRuby24?

rebase-master commented 5 years ago

@contentfree Thanks for pointing that out. I corrected that. It was there but somehow got hidden by the formatting operator.