From 8f52f1c769e1a3aa2c05d5823ee162a0e538165f Mon Sep 17 00:00:00 2001 From: Nathan Doef Date: Thu, 17 Oct 2024 07:12:21 -0400 Subject: [PATCH] Fix Regression (#6376) * failing test * fix --- .../jpa/search/builder/SearchBuilder.java | 3 +-- .../provider/r4/ResourceProviderR4Test.java | 26 +++++++++++++++++++ .../ca/uhn/fhir/jpa/test/BaseJpaTest.java | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java index ee59388c22d..8588733f5f8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java @@ -1596,7 +1596,7 @@ public class SearchBuilder implements ISearchBuilder { String sql = localReferenceQuery + " UNION " + canonicalQuery.getLeft(); - Map limitParams = null; + Map limitParams = new HashMap<>(); if (maxCount != null) { LinkedList bindVariables = new LinkedList<>(); sql = SearchQueryBuilder.applyLimitToSql( @@ -1605,7 +1605,6 @@ public class SearchBuilder implements ISearchBuilder { // The dialect SQL limiter uses positional params, but we're using // named params here, so we need to replace the positional params // with equivalent named ones - limitParams = new HashMap<>(bindVariables.size()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < sql.length(); i++) { char nextChar = sql.charAt(i); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index f5cbc222944..d97013876ea 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -2983,6 +2983,32 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertEquals(10, bundle.getTotal()); } + @Test + public void testIncludeWithNullMaxIncludesToLoad() { + myStorageSettings.setMaximumIncludesToLoadPerPage(null); + Organization org = new Organization(); + org.setName("ORG"); + IIdType orgId = myOrganizationDao.create(org, mySrd).getId().toUnqualifiedVersionless(); + + Patient pt = new Patient(); + pt.getManagingOrganization().setReference(orgId.getValue()); + pt.addName().setFamily("FAM"); + myPatientDao.create(pt, mySrd); + + Bundle bundle = myClient + .search() + .forResource(Patient.class) + .include(Patient.INCLUDE_ORGANIZATION) + .returnBundle(Bundle.class) + .execute(); + + ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); + + assertThat(bundle.getEntry()).hasSize(2); + assertEquals("Patient", bundle.getEntry().get(0).getResource().getIdElement().getResourceType()); + assertEquals("Organization", bundle.getEntry().get(1).getResource().getIdElement().getResourceType()); + } + @Test public void testIncludeWithExternalReferences() { myStorageSettings.setAllowExternalReferences(true); diff --git a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java index 2a338b75f58..de47f6e8d32 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java +++ b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java @@ -390,6 +390,7 @@ public abstract class BaseJpaTest extends BaseTest { myStorageSettings.setAdvancedHSearchIndexing(defaultConfig.isAdvancedHSearchIndexing()); myStorageSettings.setAllowContainsSearches(defaultConfig.isAllowContainsSearches()); myStorageSettings.setIncludeHashIdentityForTokenSearches(defaultConfig.isIncludeHashIdentityForTokenSearches()); + myStorageSettings.setMaximumIncludesToLoadPerPage(defaultConfig.getMaximumIncludesToLoadPerPage()); }