Rake dependency not executing but invoke works
Asked Answered
O

2

7

I've been trying to run rake db:test:clone_structure, but it keeps failing to rebuild the database. I finally looked at the task itself:

task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ]

When I run the trace, I've noticed that db:test:load_structure isn't getting executed:

$ rake db:test:clone_structure --trace
** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:structure:dump
** Invoke db:test:purge (first_time)
** Invoke environment 
** Execute db:test:purge
** Execute db:test:clone_structure

Now, when I change the clone_structure task to invoke load_structure...

task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ] do   
  db_namespace["test:load_structure"].invoke
end

...everything suddenly works!

$ rake db:test:prepare --trace

** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:structure:dump
** Invoke db:test:purge (first_time)
** Invoke environment 
** Execute db:test:purge
** Execute db:test:clone_structure
** Invoke db:test:load_structure (first_time)
** Invoke db:test:purge 
** Execute db:test:load_structure
** Invoke db:structure:load (first_time)
** Invoke environment 
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:structure:load

What could possibly be causing this behavior? I'm using Rails 3.2.14 and Rake 10.1.0.

UPDATED: I upgraded Rails to 3.2.13 from 3.2.11 and it's still a problem.

UPDATED THE SECOND: I upgraded Rails to 3.2.14 and Rake to 10.1.0 and it's still a problem

Octennial answered 8/4, 2013 at 20:31 Comment(3)
Does your structure.sql get created with no problems when you run 'rake db:test:clone_structure'? Do you see any issues with it?Sarver
Can you try running RAILS_ENV=test rake db:test:prepare --trace? I've sometimes seen that RAILS_ENV had to be set for certain tasks to get executed.Avion
@yuri: db:test:clone_structure looks like it works perfectly. I'll throw some debugs in to make sure.Octennial
O
0

After sticking a stack trace in one of the tasks I knew was being called, I found the problem. It has nothing to do with ActiveRecord or Rake and everything to do with the activerecord-oracle_enhanced-adapter gem, that I'm also using.

Basically, the gem overrides the db:test:clone_structure task like so:

redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ]

Note that it misses any reference to db:test:load_structure.

I've submitted an issue and pull request to the project, so it should hopefully be resolved in the near future.

Octennial answered 16/9, 2013 at 16:11 Comment(0)
M
1

I would say you are almost there. As far as I know the rake convention for this would be...

task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ] do   
  Rake::Task["clone_structure"].invoke
end

Otherwise, I prefer...

task :clone_structure do   
  Rake::Task["db:structure:dump"].invoke
  Rake::Task["db:test:load_structure"].invoke
end
Macey answered 5/6, 2013 at 19:6 Comment(0)
O
0

After sticking a stack trace in one of the tasks I knew was being called, I found the problem. It has nothing to do with ActiveRecord or Rake and everything to do with the activerecord-oracle_enhanced-adapter gem, that I'm also using.

Basically, the gem overrides the db:test:clone_structure task like so:

redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ]

Note that it misses any reference to db:test:load_structure.

I've submitted an issue and pull request to the project, so it should hopefully be resolved in the near future.

Octennial answered 16/9, 2013 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.