6090 requestpartitionhelpersvc throws an unexpected exception when resolving partition for non partitionable resource (#6092)

* initial failing test.

* fix and test modification

* adding changelog

---------

Co-authored-by: peartree <etienne.poirier@smilecdr.com>
This commit is contained in:
Etienne Poirier 2024-07-10 10:59:17 -04:00 committed by GitHub
parent e3f64c23a2
commit c235488580
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 5 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 6090
title: "A regression caused partition resolution to fail when creating non-partitionable resources. The issue is fixed."

View File

@ -1,6 +1,5 @@
package ca.uhn.fhir.jpa.partition;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.dao.data.IPartitionDao;
import ca.uhn.fhir.jpa.entity.PartitionEntity;
@ -8,6 +7,7 @@ import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.test.BaseJpaR4Test;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.r4.model.ConceptMap;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.BeforeEach;
@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ -52,6 +54,23 @@ class RequestPartitionHelperSvcTest extends BaseJpaR4Test {
myPatient.setId(new IdType("Patient", "123", "1"));
}
@Test
public void testDetermineReadPartitionForSystemRequest_whenResourceIsNonPartitionable_returnsDefaultPartition() {
// setup
SystemRequestDetails srd = new SystemRequestDetails();
srd.setRequestPartitionId(RequestPartitionId.allPartitions());
// execute
ConceptMap conceptMap = new ConceptMap();
RequestPartitionId result = mySvc.determineCreatePartitionForRequest(srd, conceptMap, conceptMap.fhirType());
// verify
assertThat(result.isAllPartitions()).isFalse();
assertThat(result.hasPartitionNames()).isFalse();
assertThat(result.isDefaultPartition()).isTrue();
assertThat(result.hasDefaultPartitionId()).isTrue();
}
@Test
public void testDetermineReadPartitionForSystemRequest_withPartitionIdOnly_returnsCorrectPartition() {
// setup

View File

@ -231,14 +231,14 @@ public abstract class BaseRequestPartitionHelperSvc implements IRequestPartition
}
RequestDetails requestDetails = theRequest;
boolean nonPartitionableResource = isResourceNonPartitionable(theResourceType);
// TODO GGG eventually, theRequest will not be allowed to be null here, and we will pass through
// SystemRequestDetails instead.
if (theRequest == null) {
requestDetails = new SystemRequestDetails();
if ((theRequest == null || theRequest instanceof SystemRequestDetails) && nonPartitionableResource) {
return RequestPartitionId.defaultPartition();
}
boolean nonPartitionableResource = isResourceNonPartitionable(theResourceType);
RequestPartitionId requestPartitionId = null;
if (theRequest instanceof SystemRequestDetails
&& systemRequestHasExplicitPartition((SystemRequestDetails) theRequest)) {