Repository navigation
Conversation
- 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.
schwzr
reviewed
Oct 12, 2026
Member
There was a problem hiding this comment.
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>
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.
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To run reference checks in transaction bundles a special
CheckReferencesCommandwas 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
CheckReferencesCommandand introduce a newcheckReferencesexecution phase. For a batch bundles thecheckReferencesphase is executed together with theexecutephase for every Command. While transaction bundles first run allexecutephases for all commands before running thecheckReferencesphase.Other changes:
twitter-brokerandidentity-brokering-apifeatures in dev setup keycloak.dsf-bpe-process-api-v2-implmodule.fixes #589