Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: issue could be nil (#7822)

p0nyf26616d50449
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index a61f710f33..85a3308445 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -281,7 +281,7 @@ func (s *IssueService) CreateIssue(ctx context.Context, request *v1pb.CreateIssu
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
- plan, err := s.store.GetPlan(ctx, planID)
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: &planID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan, error: %v", err)
}
@@ -824,7 +824,7 @@ func (s *IssueService) UpdateIssue(ctx context.Context, request *v1pb.UpdateIssu
patch.Payload = &payloadStr
if issue.PlanUID != nil {
- plan, err := s.store.GetPlan(ctx, *issue.PlanUID)
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: issue.PlanUID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan, error: %v", err)
}
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 7f372a1ba8..f2bbf1d2b6 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -59,7 +59,7 @@ func (s *RolloutService) GetPlan(ctx context.Context, request *v1pb.GetPlanReque
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
- plan, err := s.store.GetPlan(ctx, planID)
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: &planID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan, error: %v", err)
}
@@ -258,7 +258,7 @@ func (s *RolloutService) CreateRollout(ctx context.Context, request *v1pb.Create
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
- plan, err := s.store.GetPlan(ctx, planID)
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: &planID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan, error: %v", err)
}
@@ -340,7 +340,7 @@ func (s *RolloutService) RunPlanChecks(ctx context.Context, request *v1pb.RunPla
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
- plan, err := s.store.GetPlan(ctx, planUID)
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: &planUID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan, error: %v", err)
}
@@ -738,7 +738,7 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePla
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
- oldPlan, err := s.store.GetPlan(ctx, planID)
+ oldPlan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: &planID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get plan %q: %v", request.Plan.Name, err)
}
@@ -908,7 +908,7 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePla
return nil, status.Errorf(codes.Internal, "failed to update plan %q: %v", request.Plan.Name, err)
}
- updatedPlan, err := s.store.GetPlan(ctx, oldPlan.UID)
+ updatedPlan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: &oldPlan.UID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get updated plan %q: %v", request.Plan.Name, err)
}
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index 5a71d11cd7..199381a698 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -340,7 +340,7 @@ func getDatabaseGeneralIssueRisk(ctx context.Context, s *store.Store, licenseSer
if issue.PlanUID == nil {
return 0, store.RiskSourceUnknown, false, errors.Errorf("expected plan UID in issue %v", issue.UID)
}
- plan, err := s.GetPlan(ctx, *issue.PlanUID)
+ plan, err := s.GetPlan(ctx, &store.FindPlanMessage{UID: issue.PlanUID})
if err != nil {
return 0, store.RiskSourceUnknown, false, errors.Wrapf(err, "failed to get plan %v", *issue.PlanUID)
}
diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.go
index 61c7ecc670..ddcde64e2d 100644
--- a/backend/runner/taskrun/schedulerv2.go
+++ b/backend/runner/taskrun/schedulerv2.go
@@ -160,15 +160,12 @@ func (s *SchedulerV2) scheduleAutoRolloutTask(ctx context.Context, taskUID int)
// the latest checks of the plan must pass
pass, err := func() (bool, error) {
- if issue.PlanUID == nil {
- return true, nil
- }
- plan, err := s.store.GetPlan(ctx, *issue.PlanUID)
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{PipelineID: &task.PipelineID})
if err != nil {
return false, errors.Wrapf(err, "failed to get plan")
}
if plan == nil {
- return false, errors.Errorf("plan %d not found", *issue.PlanUID)
+ return true, nil
}
planCheckRuns, err := s.store.ListPlanCheckRuns(ctx, &store.FindPlanCheckRunMessage{PlanUID: &plan.UID})
if err != nil {
diff --git a/backend/server/webhook.go b/backend/server/webhook.go
index 17c3362324..c2a77a661e 100644
--- a/backend/server/webhook.go
+++ b/backend/server/webhook.go
@@ -2222,7 +2222,7 @@ func (s *Server) tryUpdateTasksFromModifiedFile(ctx context.Context, databases [
}
if issue.PlanUID != nil {
- plan, err := s.store.GetPlan(ctx, *issue.PlanUID)
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: issue.PlanUID})
if err != nil {
log.Error("failed to get plan", zap.Int64("plan ID", *issue.PlanUID), zap.Error(err))
}
diff --git a/backend/store/plan.go b/backend/store/plan.go
index 00f60bb158..70da072b05 100644
--- a/backend/store/plan.go
+++ b/backend/store/plan.go
@@ -103,8 +103,8 @@ func (s *Store) CreatePlan(ctx context.Context, plan *PlanMessage, creatorUID in
}
// GetPlan gets a plan.
-func (s *Store) GetPlan(ctx context.Context, uid int64) (*PlanMessage, error) {
- plans, err := s.ListPlans(ctx, &FindPlanMessage{UID: &uid})
+func (s *Store) GetPlan(ctx context.Context, find *FindPlanMessage) (*PlanMessage, error) {
+ plans, err := s.ListPlans(ctx, find)
if err != nil {
return nil, errors.Wrap(err, "failed to list plans")
}
@@ -112,7 +112,7 @@ func (s *Store) GetPlan(ctx context.Context, uid int64) (*PlanMessage, error) {
return nil, nil
}
if len(plans) > 1 {
- return nil, errors.Errorf("found multiple plans with UID %d", uid)
+ return nil, errors.Errorf("expect to find one plan, found %d", len(plans))
}
return plans[0], nil
}