Dashboard migration: v14 Broken dash repro (#110405)

* Broken dash repro

* Fix V16 migration to preserve panels when rows array is empty

- Fixed bug where panels were deleted when migrating dashboards with empty rows array
- Updated v16.go to match frontend implementation behavior
- Added test case for empty rows scenario in v16_test.go
- Renamed test files to v16.empty-rows-and-panels-array.json for clarity
- All migration tests passing (419 test cases)
This commit is contained in:
Dominik Prokop 2025-09-01 15:02:59 +02:00 committed by Jean-Philippe Quéméner
parent 3056924d10
commit 322adac5fc
4 changed files with 2198 additions and 1 deletions

View File

@ -37,7 +37,6 @@ func upgradeToGridLayout(dashboard map[string]interface{}) {
// Handle empty rows
if len(rows) == 0 {
dashboard["panels"] = []interface{}{}
delete(dashboard, "rows")
return
}

View File

@ -1392,6 +1392,72 @@ func TestV16(t *testing.T) {
},
},
},
{
name: "should preserve existing panels when rows array is empty",
input: map[string]interface{}{
"schemaVersion": 15,
"rows": []interface{}{},
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"type": "graph",
"title": "Existing Panel",
"datasource": map[string]interface{}{
"uid": "test-ds",
},
"gridPos": map[string]interface{}{
"h": 8,
"w": 12,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
"id": 2,
"type": "stat",
"title": "Another Panel",
"gridPos": map[string]interface{}{
"h": 8,
"w": 12,
"x": 12,
"y": 0,
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": 16,
// panels should be preserved exactly as they were
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"type": "graph",
"title": "Existing Panel",
"datasource": map[string]interface{}{
"uid": "test-ds",
},
"gridPos": map[string]interface{}{
"h": 8,
"w": 12,
"x": 0,
"y": 0,
},
},
map[string]interface{}{
"id": 2,
"type": "stat",
"title": "Another Panel",
"gridPos": map[string]interface{}{
"h": 8,
"w": 12,
"x": 12,
"y": 0,
},
},
},
// rows field should be removed
},
},
}
runMigrationTests(t, tests, schemaversion.V16)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff