Skip to content

Resolve Class references by name when not caching subscribers#33

Open
Nevett wants to merge 1 commit into
adambird:masterfrom
Nevett:resolve-stale-class
Open

Resolve Class references by name when not caching subscribers#33
Nevett wants to merge 1 commit into
adambird:masterfrom
Nevett:resolve-stale-class

Conversation

@Nevett
Copy link
Copy Markdown
Contributor

@Nevett Nevett commented May 8, 2026

When a Rails app using entity_store runs in development with code reloading enabled, modifying a subscriber class causes subsequent event dispatch to raise:

▎ A copy of FooService has been removed from the module tree but is still active!

The cause: EntityStore::Config.event_subscribers holds bare Class references captured at boot. After Rails unloads and reloads a class, the constant points at a fresh Class object but the registry still holds the old, dead one. EventBus#send_to_subscriber then calls .new on the dead class.

EventBus#subscribers already supports lazy resolution of String entries via EntityStore::Config.load_type. This change extends the same treatment to Class entries, gated on the existing cache_event_subscribers flag.

  • cache_event_subscribers = true (production default): Class entries are returned unchanged. Behavior unchanged.
  • cache_event_subscribers = false (typical dev/test): Class entries are re-resolved via load_type(klass.name) so the current constant binding is used.

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

Successfully merging this pull request may close these issues.

1 participant