Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

#count on decimal column returns BigDecimal

#6158

Salary.count( :amount ) # => BigDecimal instead of Fixnum

Reported by qertoip · December 13th, 2010 @ 03:44 PM

State: needs-more-info
Milestone: none
Assigned to: Josh Kalderimis Josh Kalderimis
Importance: Low

Activity

  1. Jarrett Meyer
    Jarrett Meyer

    Verified on Ubuntu + sqlite3
    ruby-1.9.2-p0 > c = Person.count(:salary)
    => #<BigDecimal:1a30a38,'0.1E1',9(18)>

    December 13th, 2010 @ 08:21 PM

  2. Jarrett Meyer
    Jarrett Meyer
    • Tag set to patch

    Added patch. Contains broken unit test and code to fix it.

    December 13th, 2010 @ 08:57 PM

  3. Thomas van der Pol
    Thomas van der Pol

    I could not replicate this problem with Rails 3.0.4 on Mac OS 10.6 with ruby 1.9.2p136

    Steps:

    1) Create new rails app (with sqlite3 as the db adapter - default)
    2) generate model with decimal column
    3) in rails console, create a few entries
    4) TestModel.count(:decimal_column) returned an integer count, not a BigDecimal

    As such, I did not try the patch. If this only happens on specific versions of rails, let me know and I'll test on them, as well.

    February 15th, 2011 @ 09:30 AM

  4. Josh Kalderimis
    Josh Kalderimis
    • Importance changed from to Low

    Hey qertoip,

    Is this a DB specific issue? or were the sqlite tests also failing with your test case?

    Josh

    February 15th, 2011 @ 04:42 PM

  5. Thomas van der Pol
    Thomas van der Pol

    As per Josh K's request, I checked the same setup as above in Postgres. (Postgres 9.0.3 on aforementioned platform: Rails 3.0.4 on Mac OS 10.6 with ruby 1.9.2p136)

    The outcome is the same:

    Salary.count(:amount).class => Fixnum

    Where Salary.amount is a decimal column in the migration, a 'numeric' type in the database itself (default behaviour).

    Cheers,
    Thomas

    February 17th, 2011 @ 12:03 PM

  6. Josh Kalderimis
    Josh Kalderimis
    • State changed from new to needs-more-info
    • Tag changed from patch to active_record
    • Assigned user set to Josh Kalderimis

    Hey qertoip and Jarrett,

    I am marking this issue as need-more-info until more information is supplied on how to replicate the issue.

    Thanks,

    Josh

    February 17th, 2011 @ 12:07 PM

  7. Jarrett Meyer
    Jarrett Meyer

    It looks like a different patch was applied to fix a similar problem that also fixed this problem - see ticket 6103.

    If I'm reading the git history correctly, this was fixed on Jan 10, 2011. The unit test in my patch file now passes. (Although there is no such unit test currently in 3.0.4.)

    February 17th, 2011 @ 01:43 PM

  8. Josh Kalderimis
    Josh Kalderimis

    Hi Jarrett,

    Thanks for looking into this, can you please create a new patch which only includes a test to make sure this does not break in the future. I will then get José or Santiago to look into it further.

    Thanks

    Josh

    February 17th, 2011 @ 01:49 PM

  9. Jarrett Meyer
  10. karle durante
    karle durante

    We use Rails w/ Oracle and have also started seeing that Model.count returns BigDecimal, as opposed to Integer.

    Seems this was introduced with Rails 2.3.8 and persists in 2.3.11.

    March 1st, 2011 @ 06:59 PM

  11. Josh Kalderimis
    Josh Kalderimis

    @Karle: As this is not a security issue it will not be applied to 2.3.x branch.

    @Jarrett: I just wanted to check, have you confirmed if this is an issue on 3-0-stable and master, or just 3.0.4?

    Thanks

    Josh

    March 2nd, 2011 @ 03:37 PM