Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition when used with Faker #87

Open
ahmgeek opened this issue Aug 31, 2024 · 4 comments
Open

Race condition when used with Faker #87

ahmgeek opened this issue Aug 31, 2024 · 4 comments

Comments

@ahmgeek
Copy link

ahmgeek commented Aug 31, 2024

Good work overall with the Oaken. Although I am sure I am using it in a twisted way, but this Code results in a race condition:

# Create some users and asooociated articles

require "faker"

puts "Creating users..."

20.times do |i|
  puts "Creating user #{i + 1}"

  User.create!(
      email: Faker::Internet.unique.email,
      name: Faker::Name.unique.name[0..20],
      bio: Faker::Lorem.paragraph[0..200],
      last_sign_in_at: Time.zone.now,
      slug: Faker::Internet.unique.slug[0..20],
      confirmed: true,
      featured: false,
      avatar: Rails.root.join("spec", "fixtures", "files", "avatar-#{rand(1..6)}.jpeg").open
  )
end

When I read the code I realized I am using it wrong. But just in case this helps with the development, the error is with the file uploading, it randomly miss uploading files with active_storage in local development. Resulting in:

web    | ActiveStorage::FileNotFoundError (ActiveStorage::FileNotFoundError):
web    |
web    | Causes:
web    | Errno::ENOENT (No such file or directory @ rb_sysopen 
@ahmgeek
Copy link
Author

ahmgeek commented Aug 31, 2024

I think it has nothing to do with faker, just the active_storage

@kaspth
Copy link
Owner

kaspth commented Sep 2, 2024

Hey thank you for using Oaken!

From the error it sounds like you've got a missing file — and Oaken isn't involved in any of those calls.

Can you double-check that you have a backing file for every value that rand(1..6) can return?

@ahmgeek
Copy link
Author

ahmgeek commented Sep 7, 2024

Thank you so much for replying.
I have files backing the random numbers. 6 files exactly.

When don't use Oaken, like just put the code directly in seeds.rb it works fine. This is why I think maybe Oaken doesn't play nice with ActiveStorage.

I can dig deeper, will let you know my findings.

@kaspth
Copy link
Owner

kaspth commented Oct 11, 2024

@ahmgeek hey, sorry for being out of the loop, did you have a chance to dig deeper?

This is why I think maybe Oaken doesn't play nice with ActiveStorage.

Oaken doesn't really do anything with Active Storage, so I'd be a bit surprised by this. Particularly, because the sample case only uses Oaken's file loading and not the orchestration API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants