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

Ticket #9472 (closed defect: duplicate)

Opened 11 months ago

Last modified 11 months ago

overiding missing_method in NilClass fails migrations

Reported by: senthil Assigned to: core
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: migration nil method_missing
Cc:

Description

we are taking our large application to beta, and I am overiding whiny nils and logging errors instead of crashing the app, as it still does not have complete testing, and third party code is being added.

If I overide missing_method in NilClass

class NilClass
def method_missing(method_name, *args,&block);end
end

create_table in migration fails, for :id column options(integer, default null, auto_increment and primary key ) is missing.

console error "Mysql::Error: You have an error in your SQL syntax;"
sql fragment in log "CREATE TABLE container_permissions (`id` , `container_id` int(11), ..."

there is no direct use of nil class in migration

NilClass#method_missing is defined in activesupport, for whiny nil, which just raises NoMethodError warning and returns strings

I have verified the behavior in 1.1.6 and edge rails

similar problem has been reported on ticket 6883 http://dev.rubyonrails.org/ticket/6883

Change History

09/04/07 05:35:47 changed by senthil

sample migration used :id has not been specified

  create_table :apples do |t|
      t.column :foo,:string
      t.column :bar,:integer
    end

09/04/07 10:07:57 changed by lifofifo

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

Duplicate of [6883]

Please reopen if the problem described in that ticket has a different solution than your problem.

09/04/07 10:13:05 changed by lifofifo

Oops.. Duplicate of #6883

09/04/07 10:38:29 changed by senthil

my issue is not with migration generation code.

rake db:migrate fails if NilClass#method_missing is overridden

when I overide NilClass#method_missing migrations using create_table where primary key is not specified and assumed to be :id ( by convention) fails.

nil is not explicitly used nor nil condition is tested in TableGeneration.

I suspect it is due to use of Struct I will submit a patch soon

09/04/07 11:22:17 changed by lifofifo

Hrmm..this might be db specific. I couldn't reproduce on MySQL 5.x

09/04/07 12:35:41 changed by senthil

tested on a clean system,It works ok in rails edge, problem only with 1.1.6, which we are using in our app

I was able to trace and have fixed my current problem,

         def type_to_sql(name, limit)
          base.type_to_sql(name, limit) rescue name
        end


def nil.[](o);   raise "nil exception during migration" end

for :id when primary key and not explicitly mentioned the above code expects an exception and returns the name parameter back. since I was overiding the exception it was failing it.

I was not convinced in using exceptions as a control flow mechanism, but looking at same code in rails edge, it feels better and more evolved,

core team is doing a good job in improving the code quality

Cheers :)