Skip to content

Fail if non-type based event handler is defined in projector#517

Merged
erikrozendaal merged 1 commit intomasterfrom
fix/fail-on-non-type-based-event-handler-in-projector
Mar 6, 2026
Merged

Fail if non-type based event handler is defined in projector#517
erikrozendaal merged 1 commit intomasterfrom
fix/fail-on-non-type-based-event-handler-in-projector

Conversation

@erikrozendaal
Copy link
Member

Since it is not possible to efficiently query the database for non-typed based event handlers (like has_attrs(...)) these are now prohibited for projectors as these event handlers were ignored by the replayer, potentially resulting in bad data in the view schema after a replay.

Rewrite the event handler to list all types that must be matched instead.

Since it is not possible to efficiently query the database for
non-typed based event handlers (like `has_attrs(...)`) these are now
prohibited for projectors as these event handlers were ignored by the
replayer, potentially resulting in bad data in the view schema after a
replay.

Rewrite the event handler to list all types that must be matched
instead.
@erikrozendaal erikrozendaal deleted the fix/fail-on-non-type-based-event-handler-in-projector branch March 6, 2026 12:30
@erikrozendaal erikrozendaal restored the fix/fail-on-non-type-based-event-handler-in-projector branch March 6, 2026 12:30
@erikrozendaal erikrozendaal reopened this Mar 6, 2026
@erikrozendaal erikrozendaal requested review from Copilot and lvonk March 6, 2026 12:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a validation to Sequent::Core::Projector that prevents non-type-based event handlers (like is_a(...), has_attrs(...), any(...)) from being defined in projectors. The rationale is that the replayer queries the database by concrete event type, so non-type-based matchers would be silently ignored during replay, potentially leading to inconsistent view state.

Changes:

  • Overrides self.on in Projector to validate that all arguments are Class instances before delegating to the parent implementation via super.
  • Adds a spec that verifies an ArgumentError is raised when a non-type-based matcher is used in a projector's on handler.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/sequent/core/projector.rb Adds self.on override that validates all args are Class before calling super
spec/lib/sequent/core/projector_spec.rb Adds test verifying ArgumentError for non-type-based event handlers in projectors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@erikrozendaal erikrozendaal merged commit 407ad17 into master Mar 6, 2026
17 checks passed
@erikrozendaal erikrozendaal deleted the fix/fail-on-non-type-based-event-handler-in-projector branch March 6, 2026 13:31
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.

2 participants