Null key overrides add null rows 2

This commit is contained in:
2026-05-13 22:22:20 +02:00
parent f3885cf93f
commit 985bffa8fb
2 changed files with 88 additions and 4 deletions
+39
View File
@@ -974,6 +974,10 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
rowByKey[rawKey] = row
}
}
if overrideRequestsNullRow(override) {
nullifyOverrideRow(row, columns, rowByKey)
continue
}
candidate := map[string]any{}
for field, value := range row {
candidate[field] = value
@@ -4058,6 +4062,41 @@ func resolveOverrideTarget(datasetName string, override map[string]any, rowByID
return nil, fmt.Errorf("dataset %s: override must specify id or key", datasetName)
}
func overrideRequestsNullRow(override map[string]any) bool {
rawKey, ok := override["key"]
if !ok {
return false
}
if rawKey == nil {
return true
}
typed, ok := rawKey.(string)
if !ok {
return false
}
return strings.TrimSpace(typed) == nullValue
}
func nullifyOverrideRow(row map[string]any, columns []string, rowByKey map[string]map[string]any) {
if oldKey, ok := row["key"].(string); ok && oldKey != "" {
if mapped, exists := rowByKey[oldKey]; exists {
mappedID, mappedHasID := mapped["id"].(int)
rowID, rowHasID := row["id"].(int)
if mappedHasID && rowHasID && mappedID == rowID {
delete(rowByKey, oldKey)
}
}
}
for field := range row {
if field != "id" {
delete(row, field)
}
}
for _, column := range columns {
row[column] = nullValue
}
}
func updateOverrideRowKey(datasetName string, row map[string]any, expanded map[string]any, rowByKey map[string]map[string]any, lockData map[string]int) (bool, error) {
oldKey, _ := row["key"].(string)
newKeyValue, hasKey := expanded["key"]