Skip to content

Commit 091beb6

Browse files
epeartreepeartree
andauthored
With partitioning selection mode set to request tenant, creating a cross partition subscription will fail if the default partition id is not null (#6748)
* initial failing test * fix with changelog and modification to previous changelog --------- Co-authored-by: peartree <[email protected]>
1 parent 1597c58 commit 091beb6

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
type: fix
33
issue: 6686
4-
title: "Previously, attempting to create a cross-partition subscription would fail if the default partition ID was
5-
assigned a value different than the default value(null). This issue is fixed."
4+
title: "With partitioning selection mode set to 'PATIENT_ID', attempting to create a cross-partition subscription
5+
would fail if the default partition ID was assigned a value different than the default value(null). This issue is fixed."
6+
67

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: fix
3+
issue: 6747
4+
title: "With partitioning selection mode set to 'REQUEST_TENANT', attempting to create a cross-partition subscription
5+
would fail if the default partition ID was assigned a value different than the default value(null). This issue is fixed."
6+

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/RequestPartitionHelperSvc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public RequestPartitionId validateAndNormalizePartitionNames(RequestPartitionId
144144
if (partition != null) {
145145
ids.add(partition.getId());
146146
} else {
147-
ids.add(null);
147+
ids.add(myPartitionSettings.getDefaultPartitionId());
148148
}
149149
}
150150
}

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/partition/RequestPartitionHelperSvcTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Set;
2222
import java.util.stream.Stream;
2323

24+
import static ca.uhn.fhir.jpa.model.util.JpaConstants.DEFAULT_PARTITION_NAME;
2425
import static org.assertj.core.api.Assertions.assertThat;
2526
import static org.junit.jupiter.api.Assertions.assertEquals;
2627
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -190,7 +191,7 @@ public void testValidateAndNormalizePartitionNames_withNameAndInvalidId_throwsEx
190191
}
191192

192193
@ParameterizedTest
193-
@MethodSource
194+
@MethodSource("withPartitionIds")
194195
public void testDefaultPartition_whenDefaultPartitionIsNotNull(Integer theRequestPartitionId) {
195196
final Integer defaultPartitionId = 0;
196197
myPartitionSettings.setDefaultPartitionId(defaultPartitionId);
@@ -206,7 +207,20 @@ public void testDefaultPartition_whenDefaultPartitionIsNotNull(Integer theReques
206207
}
207208
}
208209

209-
private static Stream<Integer> testDefaultPartition_whenDefaultPartitionIsNotNull(){
210+
@ParameterizedTest
211+
@MethodSource("withPartitionIds")
212+
public void testValidateAndNormalizePartitionNames_willResolveDefaultPartitionNameToCorrectPartitionId(Integer theDefaultPartitionId) {
213+
myPartitionSettings.setDefaultPartitionId(theDefaultPartitionId);
214+
215+
RequestPartitionId requestPartitionId = RequestPartitionId.fromPartitionName(DEFAULT_PARTITION_NAME);
216+
217+
RequestPartitionId normalizedRequestPartitionId = mySvc.validateAndNormalizePartitionNames(requestPartitionId);
218+
219+
assertThat(normalizedRequestPartitionId.isDefaultPartition(theDefaultPartitionId)).isTrue();
220+
221+
}
222+
223+
private static Stream<Integer> withPartitionIds(){
210224
return Stream.of(null, 1,2,3);
211225
}
212226

hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/partition/BaseRequestPartitionHelperSvc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private RequestPartitionId validateAndNormalizePartition(
326326
// Replace null partition ID with non-null default partition ID if one is being used
327327
if (myPartitionSettings.getDefaultPartitionId() != null
328328
&& retVal.hasPartitionIds()
329-
&& hasDefaultPartitionId(retVal)) {
329+
&& retVal.hasDefaultPartitionId(null)) {
330330
List<Integer> partitionIds = new ArrayList<>(retVal.getPartitionIds());
331331
for (int i = 0; i < partitionIds.size(); i++) {
332332
if (partitionIds.get(i) == null) {

0 commit comments

Comments
 (0)