Skip to content

Commit 8c35d0a

Browse files
fix: unmarshalling error for staging files without bytes per table (#5725)
# Description **BUG:** Unmarshalling of existing records in the `wh_staging_files` table was failing due to the `bytes_per_table` column having a default value of NULL. **FIX:** Updated the insert and read methods to handle the nil case for BytesPerTable ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used.
1 parent b1f4ce0 commit 8c35d0a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

warehouse/internal/repo/staging.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,15 @@ func (sf *StagingFiles) Insert(ctx context.Context, stagingFile *model.StagingFi
128128
if err != nil {
129129
return id, fmt.Errorf("marshaling schema: %w", err)
130130
}
131-
132-
bytesPerTableJSON, err := jsonrs.Marshal(stagingFile.BytesPerTable)
133-
if err != nil {
134-
return id, fmt.Errorf("marshaling bytes per table: %w", err)
131+
var bytesPerTablePayload interface{}
132+
if stagingFile.BytesPerTable != nil {
133+
marshalled, err := jsonrs.Marshal(stagingFile.BytesPerTable)
134+
if err != nil {
135+
return id, fmt.Errorf("marshaling bytes per table: %w", err)
136+
}
137+
bytesPerTablePayload = marshalled
138+
} else {
139+
bytesPerTablePayload = nil
135140
}
136141

137142
err = sf.db.QueryRowContext(ctx,
@@ -168,7 +173,7 @@ func (sf *StagingFiles) Insert(ctx context.Context, stagingFile *model.StagingFi
168173
now.UTC(),
169174
now.UTC(),
170175
rawMetadata,
171-
bytesPerTableJSON,
176+
bytesPerTablePayload,
172177
).Scan(&id)
173178
if err != nil {
174179
return id, fmt.Errorf("inserting staging file: %w", err)
@@ -233,9 +238,11 @@ func parseStagingFiles(rows *sqlmiddleware.Rows) ([]*model.StagingFile, error) {
233238
return nil, fmt.Errorf("unmarshal metadata: %w", err)
234239
}
235240

236-
err = jsonrs.Unmarshal(bytesPerTableRaw, &stagingFile.BytesPerTable)
237-
if err != nil {
238-
return nil, fmt.Errorf("unmarshal bytes per table: %w", err)
241+
if bytesPerTableRaw != nil {
242+
err = jsonrs.Unmarshal(bytesPerTableRaw, &stagingFile.BytesPerTable)
243+
if err != nil {
244+
return nil, fmt.Errorf("unmarshal bytes per table: %w", err)
245+
}
239246
}
240247

241248
m.SetStagingFile(&stagingFile)

0 commit comments

Comments
 (0)