Skip to content

TemplateArchiveProcessor.trigger() fails with "missing required field contract" for events extending Obligation #170

Description

@devanshi00

Summary

org.accordproject.cicero.runtime.Obligation declares a mandatory relationship back to the governing contract:

abstract event Obligation {
--> Contract contract
--> Participant promisor optional
--> Participant promisee optional
o DateTime deadline optional
}

Any event emitted by a stateful template's logic that extends Obligation (e.g. PaymentObligationEvent) inherits this required contract field. When TemplateArchiveProcessor.trigger() builds the emitted event(s) and calls Serializer.fromJSON() on them, it does not populate contract, so validation fails with:

ValidationException: The instance "<namespace>.<EventType>#<uuid>" is missing the required field "contract". ​

It reproduces on every stateful template whose logic emits an event extending Obligation, since trigger() never sets the back-reference before serializing the event. We need to extend obligation for all the events as per the discussion here:
accordproject/template-archive#937 (review)
accordproject/template-archive#937 (comment)

Reproduction

  1. Use any stateful template whose contract logic emits an event that extends org.accordproject.cicero.runtime.Obligation (e.g. a PaymentObligationEvent).
  2. Call TemplateArchiveProcessor.trigger() against that template with a valid request/state.
  3. Observe:

ValidationException: The instance "<namespace>.<EventType>#<uuid>" is missing the required field "contract". at ResourceValidator.reportMissingRequiredProperty (.../concerto-core/dist/serializer/resourcevalidator.js:528:15) at ResourceValidator.visitClassDeclaration (.../concerto-core/dist/serializer/resourcevalidator.js:255:39) at ResourceValidator.visit (.../concerto-core/dist/serializer/resourcevalidator.js:69:25) at EventDeclaration.accept (.../concerto-core/dist/introspect/decorated.js:64:24) at ValidatedResource.validate (.../concerto-core/dist/model/validatedresource.js:114:26) at Serializer.fromJSON (.../concerto-core/dist/serializer.js:171:22) at .../template-engine/lib/TemplateArchiveProcessor.js:286:60 at Array.forEach (<anonymous>) at TemplateArchiveProcessor.trigger (.../template-engine/lib/TemplateArchiveProcessor.js:286:36) ​

@dselman @mttrbrts @DianaLease

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintainer-engagedA maintainer has commented or reviewed this item

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions