Skip to content

Fix: 'contract' relationship not populated on emitted events - #171

Open
devanshi00 wants to merge 2 commits into
accordproject:mainfrom
devanshi00:main
Open

Fix: 'contract' relationship not populated on emitted events#171
devanshi00 wants to merge 2 commits into
accordproject:mainfrom
devanshi00:main

Conversation

@devanshi00

@devanshi00 devanshi00 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

org.accordproject.cicero.runtime.Obligation declares a required 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 template needs to extend Obligation (e.g. PaymentObligationEvent), thereby inheriting this required contract field, causing:

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

Changes Made

Based on @mttrbrts opinion

  • Added populateObligationBackReferences(events, data) in TemplateArchiveProcessor.trigger(), invoked immediately before the existing event-validation loop.
  • For each emitted event: skip if contract is already set (template logic can still set it explicitly)
  • If the event extends Obligation and contract is unset, and data (the contract/clause instance passed into trigger()) itself extends Contract, look up data's identifying field via modelManager.getType(data.$class).getIdentifierFieldName() and build the relationship as a "<identifierValue>" string — the correct serialized form for a relationship field than assigning the resource itself.
  • If data does not extend Contract, or its identifier can't be resolved, throw a clear error naming the offending event instead of letting the opaque ValidationException surface from resourcevalidator.js.
  • Added RUNTIME_OBLIGATION_FQN (org.accordproject.runtime@0.2.0.Obligation) and RUNTIME_CONTRACT_FQN (org.accordproject.contract@0.2.0.Contract) constants to utils.ts.

Fixes bug

#170

@mttrbrts @dselman @DianaLease

Signed-off-by: “Devanshi <117909426+devanshi00@users.noreply.github.com>
@devanshi00
devanshi00 requested a review from a team August 4, 2026 16:25
Signed-off-by: “Devanshi <117909426+devanshi00@users.noreply.github.com>
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