Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3782 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

[PATCH] mysql5 + views crashes unit testing

Reported by: japgolly@gmail.com Assigned to: David
Priority: normal Milestone: 1.1
Component: ActiveRecord Version: 1.0.0
Severity: blocker Keywords: needs_review
Cc: jonathan@bluewire.net.nz

Description

I'm using mysql 5. In the dev DB i created some views just for myself, rails doesn't use them at all and there is no reference to them in my rails app. Yet when I run "rake test_units" it crashes and won't do any tests. I've attached the rake trace:

>rake -t test_units

** Invoke test_units (first_time)
** Invoke prepare_test_database (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute prepare_test_database
** Invoke clone_structure_to_test (first_time)
** Invoke db_structure_dump (first_time)
** Invoke environment
** Execute db_structure_dump
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.+
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:236:in `structure_dump'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:235:in `inject'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:235:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:235:in `inject'
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:235:in `structure_dump'
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:42
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:42:in `open'
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:42
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:37:in `call'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:180:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:179:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:179:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:827:in `send'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:827:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:179:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:133
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/tasks/databases.rake:132:in `call'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:180:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:179:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:179:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:827:in `send'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:827:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:179:in `invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/bin/rake:7
c:/ruby/bin/rake:18:in `load'
c:/ruby/bin/rake:18

Attachments

fix_crash_with_mysql_views.patch (1.8 kB) - added by Jonathan on 03/07/06 23:47:38.
fix_crash_with_mysql_views_2.patch (1.7 kB) - added by jonathan@bluewire.net.nz on 03/08/06 09:24:50.

Change History

02/09/06 07:52:03 changed by japgolly@gmail.com

I hacked rails to make it work with mysql 5. I modified the function structure_dump in activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb

def structure_dump #:nodoc:
  select_all("SHOW FULL TABLES WHERE Table_type != 'VIEW'").inject("") do |structure, table|
    table.delete('Table_type')
    structure +=  select_one("SHOW CREATE TABLE #{table.to_a.first.last}")["Create Table"] + ";\n\n"
  end
end

Mind you this solution will crash on mysql 4 or lower because "SHOW FULL TABLES" syntax was introduced in

03/07/06 23:45:59 changed by Jonathan Viney

  • cc set to jonathan@bluewire.net.nz.
  • summary changed from mysql5 + views crashes unit testing to [PATCH] mysql5 + views crashes unit testing.

Here's a patch which should fix the problem. Let me know how it goes.

03/07/06 23:47:38 changed by Jonathan

  • attachment fix_crash_with_mysql_views.patch added.

03/08/06 09:24:31 changed by jonathan@bluewire.net.nz

I've just attached a slightly improved version of this patch. Can someone give a run on a couple of different Mysql versions?

03/08/06 09:24:50 changed by jonathan@bluewire.net.nz

  • attachment fix_crash_with_mysql_views_2.patch added.

03/14/06 11:11:08 changed by jonathan@bluewire.net.nz

  • keywords set to needs_review.

Probably not essential for 1.1, but definitely a good idea.

03/16/06 03:00:29 changed by david

  • status changed from new to closed.
  • resolution set to fixed.

(In [3886]) Stop the MySQL adapter crashing when views are present. (closes #3782) [Jonathan Viney]