Skip to content

Issue/589 invalid references via batch bundle - #590

Open
hhund wants to merge 13 commits into
developfrom
issue/589_Invalid_References_Via_Batch_Bundle
Open

hhund wants to merge 13 commits into
developfrom
issue/589_Invalid_References_Via_Batch_Bundle

Conversation

@hhund

@hhund hhund commented Oct 12, 2026

Copy link
Copy Markdown
Member

To run reference checks in transaction bundles a special CheckReferencesCommand was used previously. This command allows execution of the checks for all create and update operations on the final DB state. But this design requires a complicated error handling implementation, since two command objects existing for every POST (create) or PUT (update) entry in the bundle. The error handling implementation of batch bundles was incomplete, resulting a reference check bypass.

With this PR the batch/transaction Bundle execution implementation was refactored to remove the CheckReferencesCommand and introduce a new checkReferences execution phase. For a batch bundles the checkReferences phase is executed together with the execute phase for every Command. While transaction bundles first run all execute phases for all commands before running the checkReferences phase.

Other changes:

  • Additional integration tests
  • Disabled disabled twitter-broker and identity-brokering-api features in dev setup keycloak.
  • Added missing javaagent config for surefire tests in the ‎dsf-bpe-process-api-v2-impl module.

fixes #589

hhund added 8 commits October 12, 2026 13:08
- Removed ExceptionHandler dependency from RootServiceImpl. Method
handleBadBundleException moved to RootServiceImpl.
- Change removes CommandList <-> ExceptionHandler dependency loop.
Reference check code from CheckReferencesCommand moved into new
checkReferences execution phase of all commands. The new phase is
executed as part of execute and before DB commits for batch Bundles, but
after all executes and before the single DB commit for transaction
Bundles.
@hhund hhund added this to the 2.2.0 milestone Oct 12, 2026
@hhund
hhund requested a review from schwzr October 12, 2026 13:48
@hhund hhund self-assigned this Oct 12, 2026
@hhund hhund linked an issue Oct 12, 2026 that may be closed by this pull request

@schwzr schwzr left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now non-unique references fail with a 500 error:

package dev.dsf.fhir.integration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.UUID;

import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.Patient;
import org.junit.Test;

import dev.dsf.fhir.dao.PatientDao;
import jakarta.ws.rs.WebApplicationException;

public class Pr590PathsIntegrationTest extends AbstractIntegrationTest
{
    @Test
    public void batchConditionalCreateMultipleMatches() throws Exception
    {
        // Two existing resources match the conditional create criteria.
        PatientDao dao = getSpringWebApplicationContext().getBean(PatientDao.class);
        for (int i = 0; i < 2; i++)
        {
            Patient patient = new Patient();
            patient.addIdentifier().setSystem("urn:pr590:test").setValue("duplicate");
            dao.create(patient);
        }

        Bundle request = new Bundle().setType(BundleType.BATCH);
        request.addEntry().setFullUrl("urn:uuid:" + UUID.randomUUID())
            .setResource(new Patient().setActive(true)).getRequest()
            .setMethod(HTTPVerb.POST).setUrl("Patient")
            .setIfNoneExist("identifier=urn:pr590:test|duplicate");

        Bundle result = null;
        int actualHttpStatus = 200;
        String failureMessage = "Expected HTTP 200 with a batch-response entry containing 412 Precondition Failed";
        try
        {
            result = getWebserviceClient().postBundle(request);
        }
        catch (WebApplicationException e)
        {
            actualHttpStatus = e.getResponse().getStatus();
            failureMessage += "; actual error: " + e.getMessage();
        }

        assertEquals(failureMessage, 200, actualHttpStatus);
        assertNotNull(result);
        assertEquals(BundleType.BATCHRESPONSE, result.getType());
        assertEquals(1, result.getEntry().size());
        assertEquals("412 Precondition Failed", result.getEntryFirstRep().getResponse().getStatus());
    }
}
-------------------------------------------------------------------------------
Test set: dev.dsf.fhir.integration.Pr590PathsIntegrationTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 13.52 s <<< FAILURE! -- in dev.dsf.fhir.integration.Pr590PathsIntegrationTest
dev.dsf.fhir.integration.Pr590PathsIntegrationTest.batchConditionalCreateMultipleMatches -- Time elapsed: 0.272 s <<< FAILURE!
java.lang.AssertionError: Expected HTTP 200 with a batch-response entry containing 412 Precondition Failed; actual error: ERROR EXCEPTION Error while executing transaction bundle expected:<200> but was:<500>

hhund added 3 commits October 13, 2026 10:01
auto-commit false was previously set to early leading to a not commited
transaction if a batch bundle only included one resource and failed in
the preExecute phase. Commit or rollback only happens in the execute
phase, everything else must be auto-commit true.
@hhund

hhund commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

Now non-unique references fail with a 500 error:
...

New tests added via fff5c46, fix in 676e37c (+ code formatting f304056)

@hhund
hhund requested a review from schwzr October 13, 2026 09:34
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.

Resources With Invalid References Can Be Created Via Batch Bundle

3 participants