Skip to content

OFBIZ-13461 : Avoid async RequirementStatus FK race after createRequirement#1480

Open
diveshdut wants to merge 2 commits into
apache:trunkfrom
diveshdut:mrp-requirement-status-fk
Open

OFBIZ-13461 : Avoid async RequirementStatus FK race after createRequirement#1480
diveshdut wants to merge 2 commits into
apache:trunkfrom
diveshdut:mrp-requirement-status-fk

Conversation

@diveshdut

@diveshdut diveshdut commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Jira ticket:

https://issues.apache.org/jira/browse/OFBIZ-13461

Summary

This fixes a timing-dependent foreign-key failure during requirement status creation.

When createRequirement runs inside a larger transaction, its async SECA can invoke createRequirementStatus before the enclosing transaction has fully committed. In that window, the new Requirement row is not yet visible, and the RequirementStatus insert can fail with:

REQ_STTS_REQ: OFBIZ.REQUIREMENT_STATUS FOREIGN KEY(REQUIREMENT_ID) REFERENCES OFBIZ.REQUIREMENT(REQUIREMENT_ID)

This was observed from the Manufacturing Run MRP flow, but the underlying bug is in the order-side requirement status SECA behavior.

Root Cause

The existing createRequirement SECA used event="commit" with mode="async".

That is not a safe boundary when createRequirement participates in an outer transaction. The async follow-up may run before the outer transaction is committed and globally visible.

This is a race condition rather than a deterministic logic error.

Changes

  • changed the createRequirement status SECA to global-commit-post-run
  • changed the updateRequirement status SECA to global-commit
  • added a focused order-side regression test for the outer-transaction scenario
  • registered the regression test in the order test suite

Why global-commit-post-run

createRequirementStatus needs the generated requirementId.

global-commit-post-run ensures:

  • the enclosing transaction has committed
  • the generated service output is still available to the follow-up async action

Tests

Added a focused regression test for the outer-transaction timing case:

  • RequirementStatusEcaTests.testCreateRequirementStatusAfterOuterTransactionCommit

This verifies that:

  • createRequirement can run inside an outer transaction
  • RequirementStatus is not created before commit
  • RequirementStatus is created successfully after commit

@diveshdut diveshdut changed the title Mrp requirement status fk OFBIZ-13461 : Avoid async RequirementStatus FK race after createRequirement Jul 22, 2026
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