Skip to content

Inline ActiveJob clears CurrentAttributes erroneously #37526

@jpcody

Description

@jpcody

Steps to reproduce

  1. Set a value during seeding in a class that inherits from ActiveSupport::CurrentAttributes
  2. Run code that enqueues a job via ActiveJob (e.g. uploading a file via ActiveStorage)
  3. Note that the value from step 1 is cleared

Because the database is seeded with the inline adapter, jobs run inline in seeding. When the job is run, the executor resets all current attributes. Here's a commit that exhibits the issue.

In my app, I'm iterating over customers and seeding a logo for each then seeding users for each. The iteration uses Current.set(customer: customer) { yield }, and within the yield we attach a logo. After that logo is attached, Current.customer is reset to nil because ActiveStorage::AnalyzeJob.perform_later(self) runs .

Expected behavior

Jobs run inline should not clear CurrentAttributes.

Actual behavior

CurrentAttributes are cleared.

System configuration

Rails version: Rails 6.0.0
Ruby version: ruby 2.6.5p114

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions