Validate panels in Store.AddPanel/UpdatePanel, not just at the handler

CreateDashboard's inline panel-creation path already called
validatePanel before insert; AddPanel and UpdatePanel relied on the
HTTP handler to validate first instead of enforcing it themselves.
Found via a live Postgres integration test: calling store.AddPanel
directly (bypassing the handler) hit a viz_config NOT NULL constraint
violation instead of getting the same default-empty-JSON treatment
every other panel-creation path gets.
This commit is contained in:
2026-08-15 17:17:16 -07:00
parent e15a63408a
commit 5365c92ffa
+6
View File
@@ -183,6 +183,9 @@ func (s *Store) DeleteDashboard(ctx context.Context, tenantID, id string) error
}
func (s *Store) AddPanel(ctx context.Context, tenantID, dashboardID string, p *Panel) error {
if err := validatePanel(p); err != nil {
return err
}
ok, err := s.dashboardTenantMatches(ctx, tenantID, dashboardID)
if err != nil {
return err
@@ -203,6 +206,9 @@ func (s *Store) AddPanel(ctx context.Context, tenantID, dashboardID string, p *P
}
func (s *Store) UpdatePanel(ctx context.Context, tenantID string, p *Panel) error {
if err := validatePanel(p); err != nil {
return err
}
ok, err := s.dashboardTenantMatches(ctx, tenantID, p.DashboardID)
if err != nil {
return err