Skip to content

Commit 45739f5

Browse files
author
Cameron Custer
committed
bug fix for subscription usage info unmarshalling when group by is used
1 parent 120f8d3 commit 45739f5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

subscription.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5276,13 +5276,20 @@ func init() {
52765276
apijson.RegisterUnion(
52775277
reflect.TypeOf((*SubscriptionUsageUnion)(nil)).Elem(),
52785278
"",
5279+
// Prefer the grouped variant when both variants appear equally exact.
5280+
// With both TypeFilters as gjson.JSON and no discriminator, the union
5281+
// resolver breaks ties left-to-right. Grouped responses include a
5282+
// `metric_group` field on each data element, which would otherwise be
5283+
// treated as an extra field by the ungrouped type, causing the ungrouped
5284+
// variant to win incorrectly. Listing the grouped variant first ensures
5285+
// grouped responses select the grouped type so metric_group is preserved.
52795286
apijson.UnionVariant{
52805287
TypeFilter: gjson.JSON,
5281-
Type: reflect.TypeOf(SubscriptionUsageUngroupedSubscriptionUsage{}),
5288+
Type: reflect.TypeOf(SubscriptionUsageGroupedSubscriptionUsage{}),
52825289
},
52835290
apijson.UnionVariant{
52845291
TypeFilter: gjson.JSON,
5285-
Type: reflect.TypeOf(SubscriptionUsageGroupedSubscriptionUsage{}),
5292+
Type: reflect.TypeOf(SubscriptionUsageUngroupedSubscriptionUsage{}),
52865293
},
52875294
)
52885295
}

0 commit comments

Comments
 (0)