Skip to content

Running rails db:seed with File I/O will cause process to hang #33500

@RigoOnRails

Description

@RigoOnRails

Steps to reproduce

  • Install ActiveStorage
  • Create a Post model with rails g model Post title:string & migrate
  • Add has_one_attached :image to the Post model
  • Add this code to db/seeds.rb:
post = Post.create(title: 'Test post')
post.image.attach(io: File.open("#{Rails.root}/test.png"), filename: "test.png")
  • Add a sample image with the file name test.png at the Rails root directory
  • Run rails db:drop db:create db:migrate db:seed

Expected behavior

rails db:seed should run & exit successfully.

Actual behavior

rails db:seed will successfully seed the database but it will not exit the process.

System configuration

Rails version: 5.2.0

Ruby version: ruby 2.5.1p57

Attempts to fix

I tried referencing the file by a variable image = File.open("#{Rails.root}/test.png") & then attaching it to the post like this post.image.attach(io: image, filename: "test.png") & finally closing the file with image.close. It still caused the process to hang.

Workaround

Adding config.active_job.queue_adapter = :inline to config/environments/development.rb will fix the issue for some reason, I'm not quite sure why. That's why I'm guessing this issue has something to do with the inner workings of ActiveJob.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions