Skip to content

Commit ab58eda

Browse files
committed
Wrap database seeding in a reload
It is quite possible that database seeding may run jobs inline. In that case a reload will be attempted. For app that is set to reload_classes_only_on_change this would normally not initiate a reload, since no files would have been changed. However, it is common to run the seeds as part of one command that also sets up the database (eg bin/rails db:prepare db:seed). In that case, the schema.rb file may have changes. By default that file is watched by the reloader. So, the application will be reloaded at the time the first job (or other reload) occurs. Reloading the application during the middle of running seeds can lead to unexpected and buggy behaviour. Instead, we should wrap the entire seeds task in a reload so that the reload only occurs at the end of seeding.
1 parent 281a00a commit ab58eda

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

railties/lib/rails/engine.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,9 @@ def load_seed
648648
end
649649
end
650650

651-
initializer :wrap_executor_around_load_seed do |app|
651+
initializer :wrap_reloader_around_load_seed do |app|
652652
self.class.set_callback(:load_seed, :around) do |engine, seeds_block|
653-
app.executor.wrap(&seeds_block)
653+
app.reloader.wrap(&seeds_block)
654654
end
655655
end
656656

0 commit comments

Comments
 (0)