Skip to content

Commit 2055070

Browse files
authored
fix(createforecast): Correctly set empty value metadata to NULL (#128)
1 parent fb9bb7f commit 2055070

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

internal/server/postgres/dataserverimpl.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ func (s *DataPlatformDataServiceServerImpl) CreateForecast(
182182
roundedStats[k] = roundedVal
183183
}
184184

185+
// Since CreatePredictedValues uses COPYFROM, manually coerce empty metadata to nil
186+
if value.Metadata != nil && len(value.Metadata.Fields) == 0 {
187+
value.Metadata = nil
188+
}
189+
185190
var otherStats *structpb.Struct
186191

187192
if len(roundedStats) > 0 {

internal/server/postgres/dataserverimpl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ func TestCreateForecast(t *testing.T) {
15181518
HorizonMins: uint32(i * 30),
15191519
P50Fraction: 0.0,
15201520
OtherStatisticsFractions: map[string]float32{},
1521-
Metadata: nil,
1521+
Metadata: &structpb.Struct{},
15221522
}
15231523
}
15241524

@@ -1550,7 +1550,7 @@ func TestCreateForecast(t *testing.T) {
15501550
},
15511551
},
15521552
{
1553-
name: "Should create forecast with zeroed values",
1553+
name: "Should create forecast with zeroed values and metadata",
15541554
req: &pb.CreateForecastRequest{
15551555
LocationUuid: siteResp.LocationUuid,
15561556
Forecaster: fcResp.Forecaster,

0 commit comments

Comments
 (0)