From 208c85c0d98e4ffdc12f912d01471e3b01d963d7 Mon Sep 17 00:00:00 2001 From: Patrick Werner Date: Thu, 13 Nov 2025 09:15:04 +0100 Subject: [PATCH 1/3] refactor: update request partition handling to use configured default --- .../ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java index 5b4b7d65c10b..85a38a84484b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java @@ -27,7 +27,6 @@ import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.i18n.Msg; -import ca.uhn.fhir.interceptor.model.RequestPartitionId; import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; @@ -188,7 +187,7 @@ public PackageInstallOutcomeJson install(PackageInstallationSpec theInstallation boolean exists = myTxService .withSystemRequest() - .withRequestPartitionId(RequestPartitionId.defaultPartition()) + .withRequestPartitionId(myPartitionSettings.getDefaultRequestPartitionId()) .execute(() -> { Optional existing = myPackageVersionDao.findByPackageIdAndVersion( theInstallationSpec.getName(), theInstallationSpec.getVersion()); @@ -550,10 +549,11 @@ private DaoMethodOutcome updateResource(IFhirResourceDao theDao, IBaseResource t return outcome; } - private RequestDetails createRequestDetails() { + @VisibleForTesting + RequestDetails createRequestDetails() { SystemRequestDetails requestDetails = new SystemRequestDetails(); if (myPartitionSettings.isPartitioningEnabled()) { - requestDetails.setRequestPartitionId(RequestPartitionId.defaultPartition()); + requestDetails.setRequestPartitionId(myPartitionSettings.getDefaultRequestPartitionId()); } return requestDetails; } From 5e5d63f74ce1d5fe16a4c3092ffe7477dd061106 Mon Sep 17 00:00:00 2001 From: Patrick Werner Date: Thu, 13 Nov 2025 09:15:15 +0100 Subject: [PATCH 2/3] test: add unit tests for default partition handling in request details --- .../packages/PackageInstallerSvcImplTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImplTest.java index 8357c11618e5..20b594e715de 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImplTest.java @@ -3,6 +3,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.support.IValidationSupport; +import ca.uhn.fhir.interceptor.model.RequestPartitionId; import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; @@ -17,6 +18,7 @@ import ca.uhn.fhir.jpa.searchparam.util.SearchParameterHelper; import ca.uhn.fhir.mdm.log.Logs; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.api.server.SystemRequestDetails; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.hapi.converters.canonical.VersionCanonicalizer; @@ -230,6 +232,40 @@ public void testValidForUpload_WhenSearchParameterValidatorThrowsAnExceptionOthe + @Test + public void testCreateRequestDetailsUsesDefaultPartition() { + myPartitionSettings.setPartitioningEnabled(true); + myPartitionSettings.setDefaultPartitionId(42); + + RequestDetails requestDetails = mySvc.createRequestDetails(); + assertTrue(requestDetails instanceof SystemRequestDetails); + SystemRequestDetails systemRequestDetails = (SystemRequestDetails) requestDetails; + + assertEquals(RequestPartitionId.fromPartitionId(42), systemRequestDetails.getRequestPartitionId()); + } + + @Test + public void testInstallPackageUsesDefaultPartition() throws IOException { + myPartitionSettings.setPartitioningEnabled(true); + myPartitionSettings.setDefaultPartitionId(7); + + CodeSystem newCodeSystem = new CodeSystem(); + newCodeSystem.setId("CodeSystem/newcs"); + newCodeSystem.setUrl("http://partitioned-code-system"); + newCodeSystem.setContent(CodeSystem.CodeSystemContentMode.COMPLETE); + + PackageInstallationSpec spec = setupResourceInPackage(null, newCodeSystem, myCodeSystemDao); + + mySvc.install(spec); + + verify(myCodeSystemDao).create(any(CodeSystem.class), myRequestDetailsCaptor.capture()); + RequestDetails requestDetails = myRequestDetailsCaptor.getValue(); + + assertTrue(requestDetails instanceof SystemRequestDetails); + SystemRequestDetails systemRequestDetails = (SystemRequestDetails) requestDetails; + assertEquals(RequestPartitionId.fromPartitionId(7), systemRequestDetails.getRequestPartitionId()); + } + @Test public void testDontTryToInstallDuplicateCodeSystem_CodeSystemAlreadyExistsWithDifferentId() throws IOException { // Setup From 85052d70bb5abbc9ae80b81554b3503f442428f9 Mon Sep 17 00:00:00 2001 From: Patrick Werner Date: Thu, 13 Nov 2025 09:18:10 +0100 Subject: [PATCH 3/3] add changelog entry --- .../8_6_0/7375-fix-packageInstallation-withPartitions.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/8_6_0/7375-fix-packageInstallation-withPartitions.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/8_6_0/7375-fix-packageInstallation-withPartitions.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/8_6_0/7375-fix-packageInstallation-withPartitions.yaml new file mode 100644 index 000000000000..0aca66db99c9 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/8_6_0/7375-fix-packageInstallation-withPartitions.yaml @@ -0,0 +1,4 @@ +--- +type: fix +issue: 7375 +title: "PackageInstallerSvcImpl now consistently applies the default partition when running in STORE_AND_INSTALL mode. Terminology resources imported from NPM packages no longer fail in partitioned JPA servers with the error about writing a non-partitionable resource into a partition."