This project is archived and is in readonly mode.

#5549 ✓stale
Hunter

ActiveRecord::Calculations.count( ) not work , when mysql table is empty

Reported by Hunter | September 3rd, 2010 @ 04:06 PM

it can works well in rails2.3.5, now failed in rails3, it getting bad.

C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connect
ion_adapters/mysql_adapter.rb:629:in select': undefined methodall_hashes' for
#<Mysql::Result:0x19b94c8> (NoMethodError)

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/connection_adapters/abstract/database_statements.rb:7:in select_all'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/connection_adapters/abstract/query_cache.rb:56:in select_all'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/connection_adapters/abstract/database_statements.rb:13:in select_one'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/connection_adapters/abstract/database_statements.rb:19:in select_value'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/relation/calculations.rb:196:in execute_simple_calculation'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/relation/calculations.rb:183:in perform_calculation'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/relation/calculations.rb:152:in calculate'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r

ecord/relation/calculations.rb:58:in count'<br/>

    from C:in `count'
    from D:/vob/g2/config/initializers/cargo_category_load.rb:95:in `<top (r

equired)>'

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_

support/dependencies.rb:235:in load'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_

support/dependencies.rb:235:in block in load'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_

support/dependencies.rb:225:in block in load_dependency'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_

support/dependencies.rb:591:in new_constants_in'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_

support/dependencies.rb:225:in load_dependency'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_

support/dependencies.rb:235:in load'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine

.rb:201:in block (2 levels) in <class:Engine>'

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine

.rb:200:in each'

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine

.rb:200:in block in <class:Engine>'

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initia

lizable.rb:25:in instance_exec'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initia

lizable.rb:25:in run'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initia

lizable.rb:50:in block in run_initializers'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initia

lizable.rb:49:in each'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initia

lizable.rb:49:in run_initializers'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/applic

ation.rb:134:in initialize!'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/applic

ation.rb:77:in method_missing'<br/>

    from D:/vob/g2/config/environment.rb:5:in `<top (required)>'
    from D:/vob/g2/config.ru:3:in `require'
    from D:/vob/g2/config.ru:3:in `block in <main>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:

46:in instance_eval'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:

46:in initialize'<br/>

    from D:/vob/g2/config.ru:1:in `new'
    from D:/vob/g2/config.ru:1:in `<main>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:

35:in eval'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:

35:in parse_file'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:1

62:in app'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:2

48:in wrapped_app'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:2

13:in start'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/comman

ds/server.rb:65:in start'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/comman

ds.rb:30:in block in <top (required)>'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/comman

ds.rb:27:in tap'<br/>

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/comman

ds.rb:27:in <top (required)>'<br/>

    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Comments and changes to this ticket

  • Neeraj Singh

    Neeraj Singh September 3rd, 2010 @ 06:38 PM

    • Importance changed from “” to “Low”

    Can you post the query that is breaking?

  • Hunter

    Hunter September 4th, 2010 @ 02:59 AM

    the trace stack is already in the post.

    extract the excetion for count here:

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_r
    ecord/relation/calculations.rb:58:in count'

    from C:in `count'
    from D:/vob/g2/config/initializers/cargo_category_load.rb:95:in `<top (r
    

    equired)>'

    mysql_adapter.rb:629:in select': undefined methodall_hashes' for

    <Mysql::Result:0x19b94c8> (NoMethodError)

    , and not only for count , but also for other method, like all, will get same break.

  • David Trasbo

    David Trasbo September 5th, 2010 @ 06:31 PM

    I was unable to reproduce this on edge Rails using Ruby 1.9.2:

    
    ➜  in ~/code/rails/railties/tmp on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp ../../bin/rails new ticket_5549 --dev -d mysql
    ...
    ➜  in ~/code/rails/railties/tmp on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp cd ticket_5549 
    ➜  in ~/code/rails/railties/tmp/ticket_5549 on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp bundle exec rails g model foo
    ...
    ➜  in ~/code/rails/railties/tmp/ticket_5549 on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp rake db:create
    (in /Users/dtrasbo/code/rails/railties/tmp/ticket_5549)
    ➜  in ~/code/rails/railties/tmp/ticket_5549 on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp rake db:migrate
    (in /Users/dtrasbo/code/rails/railties/tmp/ticket_5549)
    ..
    ➜  in ~/code/rails/railties/tmp/ticket_5549 on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp cat config/database.yml 
    # MySQL.  Versions 4.1 and 5.0 are recommended.
    #
    # Install the MySQL driver:
    #   gem install mysql2
    #
    # And be sure to use new-style password hashing:
    #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
    development:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: ticket_5549_development
      pool: 5
      username: root
      password:
      socket: /tmp/mysql.sock
    
    test:
    ...
    ➜  in ~/code/rails/railties/tmp/ticket_5549 on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp bundle exec rails c 
    Loading development environment (Rails 3.1.0.beta)
    ruby-1.9.2-p0 > Foo.count
     => 0 
    ruby-1.9.2-p0 > exit
    ➜  in ~/code/rails/railties/tmp/ticket_5549 on 5549 (✔) using ruby-1.9.2-p0@edgerailsapp mysql --version
    mysql  Ver 14.14 Distrib 5.1.49, for apple-darwin10.4.0 (i386) using readline 6.0
    

    I'm on OS X.

  • David Trasbo

    David Trasbo September 5th, 2010 @ 06:36 PM

    That turned out to be a bit crufty. Here we go again:

    ➜ ../../bin/rails new ticket_5549 --dev -d mysql...
    ➜ cd ticket_5549 ➜ bundle exec rails g model foo...
    ➜ rake db:create(in /Users/dtrasbo/code/rails/railties/tmp/ticket_5549)
    ➜ rake db:migrate(in /Users/dtrasbo/code/rails/railties/tmp/ticket_5549)
    ..
    ➜ cat config/database.yml # MySQL.  Versions 4.1 and 5.0 are recommended.
    #
    # Install the MySQL driver:
    #   gem install mysql2
    #
    # And be sure to use new-style password hashing:
    #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
    development:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: ticket_5549_development
      pool: 5
      username: root
      password:
      socket: /tmp/mysql.sock
    
    test:
    ...
    ➜ bundle exec rails c Loading development environment (Rails 3.1.0.beta)
    ruby-1.9.2-p0 > Foo.count
     => 0 
    ruby-1.9.2-p0 > exit
    ➜ mysql --versionmysql  Ver 14.14 Distrib 5.1.49, for apple-darwin10.4.0 (i386) using readline 6.0
    
  • Hunter

    Hunter September 7th, 2010 @ 02:37 AM

    Hi, Thanks for your quick action on this fault.

    Something clarify here.

    1. I use mysql gem rather than mysql2

    2. I am on windows platform

    3. when I switch back to Rails 2.3.5, everything ok, and no exception .

    Brs

    Hunter Hu

  • David Trasbo

    David Trasbo September 7th, 2010 @ 12:25 PM

    Ah, okay. I repeated the process above except I used the mysql adapter/gem instead but I still couldn't reproduce. That leaves Windows.

    I do have access to a Windows machine with Ruby but I won't be near it before tomorrow. I'll try and see if I can reproduce this then.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:32 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:32 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages