Skip to content

Commit

Permalink
Protect against prevRow being a nil map
Browse files Browse the repository at this point in the history
  • Loading branch information
danafallon committed Jun 25, 2024
1 parent 70648ec commit 37bfb8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/optimization/table_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func (t *TableData) InsertRow(pk string, rowData map[string]any, delete bool) {
if delete {
// if the row was deleted, copy the previous values and just update the deleted flag
rowData = prevRow
if _, isOk := rowData[constants.DeleteColumnMarker]; !isOk {
rowData = map[string]any{}
}
rowData[constants.DeleteColumnMarker] = true
} else {
for key, val := range rowData {
Expand Down
4 changes: 2 additions & 2 deletions lib/optimization/table_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ func TestTableData_InsertRowIntegrity(t *testing.T) {
assert.False(t, td.ContainOtherOperations())

for i := 0; i < 100; i++ {
td.InsertRow("123", map[string]any{}, true)
td.InsertRow("123", nil, true)
assert.False(t, td.ContainOtherOperations())
}

for i := 0; i < 100; i++ {
td.InsertRow("123", map[string]any{}, false)
td.InsertRow("123", nil, false)
assert.True(t, td.ContainOtherOperations())
}
}

0 comments on commit 37bfb8d

Please sign in to comment.