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

Event subscribers loaded twice with Rails 6/Zeitwerk #3757

Closed
spaghetticode opened this issue Sep 11, 2020 · 0 comments · Fixed by #3758
Closed

Event subscribers loaded twice with Rails 6/Zeitwerk #3757

spaghetticode opened this issue Sep 11, 2020 · 0 comments · Fixed by #3758
Assignees
Labels
type:bug Error, flaw or fault

Comments

@spaghetticode
Copy link
Member

Solidus Version:
master

Description

Custom defined event subscriber modules may end up being subscribed twice (or more!) on Solidus apps based on Rails 6.x. I was not able to reproduce this issue on Rails 5.2.

The problem happens only in development (or more generally when classes are not cached) and when event subscribers are loaded using initializers, as we used to suggest in the Event section of Solidus documentation.

Apparently, the issue is related to the new Zeitwerk autoload.

The simplest fix for this is to simply remove the offending initializers. Subscribers will be loaded automatically anyways thanks to #3571.

If for any reason somebody does not want to remove the initializers or wants to experiment with the issue, by explicitly requiring the subscriber file in the initializer will fix it:

require Rails.root.join('app/subscribers/custom_subscriber')

CustomSubscriber.subscribe!

I'm working on a more robust solution (a centralized way to track event subscribers subscriptions) that will completely remove the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant