Skip to content

strengthen binding between Event.type and Event.target #7744

@cfm

Description

@cfm

In the v2 Journalist API, events are explicitly typed as a 2-tuple of:

  1. Event.type
  2. Event.data (optional)

It occurs to me that they are implicitly typed further as a 3-tuple of (1) and (2) plus:

  1. Event.target

Although (2) is optional, it's strong: An event will be rejected if its data has the wrong schema for its type.

By contrast, although (3) is required, it's weak: A handler will attempt to process an event with a valid target of the wrong schema, for example an ItemDeleted event with a SourceTarget instead of an ItemTarget. The handler will fail correctly, but it will fail while handling the event rather than while validating it.

I see three options:

  1. Do nothing. Events with invalid targets will continue to fail during handling rather than validation.
  2. Define EVENT_TARGET_TYPES just like EVENT_DATA_TYPES. Reject events with invalid targets during validation.
  3. Define a parameterized decorator. Let individual handler methods reject events with unexpected targets, e.g.:
    • @expect(SourceTarget)
    • @expect(ItemTarget)
    • @expect(ItemTarget, SourceTarget)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Ready to go

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions