Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: use correct stage ID placeholder in issue comment task names (#18242)
boojackb7327248e408
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.goindex 8a21235f67..431c00b87c 100644--- a/backend/api/v1/rollout_service_converter.go+++ b/backend/api/v1/rollout_service_converter.go@@ -15,22 +15,9 @@ import ("github.com/bytebase/bytebase/backend/store")-const (- // emptyStageID is the placeholder used for stages without environment or with deleted environments.- emptyStageID = "-"-)--// formatStageIDFromEnvironment returns the stage ID, using emptyStageID placeholder if environment is empty.-func formatStageIDFromEnvironment(environment string) string {- if environment == "" {- return emptyStageID- }- return environment-}--// formatEnvironmentFromStageID converts stage ID back to environment, handling the emptyStageID placeholder.+// formatEnvironmentFromStageID converts stage ID back to environment, handling the EmptyStageID placeholder.func formatEnvironmentFromStageID(stageID string) string {- if stageID == emptyStageID {+ if stageID == common.EmptyStageID {return ""}return stageID@@ -49,7 +36,7 @@ func convertToTaskRuns(ctx context.Context, s *store.Store, stateCfg *state.Stat}func convertToTaskRun(ctx context.Context, s *store.Store, stateCfg *state.State, taskRun *store.TaskRunMessage) (*v1pb.TaskRun, error) {- stageID := formatStageIDFromEnvironment(taskRun.Environment)+ stageID := common.FormatStageID(taskRun.Environment)t := &v1pb.TaskRun{Name: common.FormatTaskRun(taskRun.ProjectID, taskRun.PipelineUID, stageID, taskRun.TaskUID, taskRun.ID),Creator: common.FormatUserEmail(taskRun.Creator.Email),@@ -159,7 +146,7 @@ func convertToSchedulerInfoWaitingCause(ctx context.Context, s *store.Store, c *if issue != nil {issueName = common.FormatIssue(issue.Project.ResourceID, issue.UID)}- stageID := formatStageIDFromEnvironment(task.Environment)+ stageID := common.FormatStageID(task.Environment)return &v1pb.TaskRun_SchedulerInfo_WaitingCause{Cause: &v1pb.TaskRun_SchedulerInfo_WaitingCause_Task_{Task: &v1pb.TaskRun_SchedulerInfo_WaitingCause_Task{@@ -284,7 +271,7 @@ func convertToRollout(ctx context.Context, s *store.Store, project *store.Projecfor _, environment := range environmentOrder {tasks := tasksByEnv[environment]if len(tasks) > 0 {- stageID := formatStageIDFromEnvironment(environment)+ stageID := common.FormatStageID(environment)stages = append(stages, &v1pb.Stage{Name: common.FormatStage(project.ResourceID, rollout.ID, stageID),Id: stageID,@@ -297,7 +284,7 @@ func convertToRollout(ctx context.Context, s *store.Store, project *store.Projecfor environment, tasks := range tasksByEnv {if len(tasks) > 0 {- stageID := formatStageIDFromEnvironment(environment)+ stageID := common.FormatStageID(environment)stages = append([]*v1pb.Stage{{Name: common.FormatStage(project.ResourceID, rollout.ID, stageID),@@ -346,7 +333,7 @@ func convertToTaskFromDatabaseCreate(ctx context.Context, s *store.Store, projecif err != nil {return nil, errors.Wrapf(err, "failed to get instance %s", task.InstanceID)}- stageID := formatStageIDFromEnvironment(task.Environment)+ stageID := common.FormatStageID(task.Environment)v1pbTask := &v1pb.Task{Name: common.FormatTask(project.ResourceID, task.PipelineID, stageID, task.ID),SpecId: task.Payload.GetSpecId(),@@ -407,7 +394,7 @@ func convertToTaskFromSchemaUpdate(ctx context.Context, s *store.Store, projectdatabaseChangeType = v1pb.DatabaseChangeType_DATABASE_CHANGE_TYPE_UNSPECIFIED}- stageID := formatStageIDFromEnvironment(task.Environment)+ stageID := common.FormatStageID(task.Environment)v1pbTask := &v1pb.Task{Name: common.FormatTask(project.ResourceID, task.PipelineID, stageID, task.ID),SpecId: task.Payload.GetSpecId(),@@ -445,7 +432,7 @@ func convertToTaskFromDataUpdate(ctx context.Context, s *store.Store, project *sreturn nil, errors.Errorf("database not found")}- stageID := formatStageIDFromEnvironment(task.Environment)+ stageID := common.FormatStageID(task.Environment)v1pbTask := &v1pb.Task{Name: common.FormatTask(project.ResourceID, task.PipelineID, stageID, task.ID),SpecId: task.Payload.GetSpecId(),@@ -495,7 +482,7 @@ func convertToTaskFromDatabaseDataExport(ctx context.Context, s *store.Store, prPassword: &task.Payload.Password,},}- stageID := formatStageIDFromEnvironment(task.Environment)+ stageID := common.FormatStageID(task.Environment)v1pbTask := &v1pb.Task{Name: common.FormatTask(project.ResourceID, task.PipelineID, stageID, task.ID),SpecId: task.Payload.GetSpecId(),diff --git a/backend/common/resource_name.go b/backend/common/resource_name.goindex 418f9d0a5f..f1995c1edc 100644--- a/backend/common/resource_name.go+++ b/backend/common/resource_name.go@@ -560,6 +560,17 @@ func FormatRollout(projectID string, pipelineUID int) string {return fmt.Sprintf("%s/%s%d", FormatProject(projectID), RolloutPrefix, pipelineUID)}+// EmptyStageID is the placeholder used for stages without environment or with deleted environments.+const EmptyStageID = "-"++// FormatStageID returns the stage ID, using EmptyStageID placeholder if environment is empty.+func FormatStageID(environment string) string {+ if environment == "" {+ return EmptyStageID+ }+ return environment+}+// stageID is task environmentID.func FormatStage(projectID string, pipelineUID int, stageID string) string {return fmt.Sprintf("%s/%s%s", FormatRollout(projectID, pipelineUID), StagePrefix, stageID)diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.goindex 232d89f2cf..38a5466e27 100644--- a/backend/runner/taskrun/schedulerv2.go+++ b/backend/runner/taskrun/schedulerv2.go@@ -260,7 +260,7 @@ func (s *SchedulerV2) scheduleAutoRolloutTask(ctx context.Context, taskUID int)}if issue != nil {- tasks := []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.Environment, taskUID)}+ tasks := []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, common.FormatStageID(task.Environment), taskUID)}if err := s.store.CreateIssueCommentTaskUpdateStatus(ctx, issue.UID, tasks, storepb.TaskRun_PENDING, common.SystemBotID, ""); err != nil {slog.Warn("failed to create issue comment", "issueUID", issue.UID, log.BBError(err))}@@ -672,7 +672,7 @@ func (s *SchedulerV2) runTaskRunOnce(ctx context.Context, taskRun *store.TaskRunif issue == nil {return nil}- tasks := []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.Environment, task.ID)}+ tasks := []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, common.FormatStageID(task.Environment), task.ID)}return s.store.CreateIssueCommentTaskUpdateStatus(ctx, issue.UID, tasks, storepb.TaskRun_FAILED, common.SystemBotID, "")}(); err != nil {slog.Warn("failed to create issue comment", log.BBError(err))@@ -716,7 +716,7 @@ func (s *SchedulerV2) runTaskRunOnce(ctx context.Context, taskRun *store.TaskRunif issue == nil {return nil}- tasks := []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, task.Environment, task.ID)}+ tasks := []string{common.FormatTask(issue.Project.ResourceID, task.PipelineID, common.FormatStageID(task.Environment), task.ID)}return s.store.CreateIssueCommentTaskUpdateStatus(ctx, issue.UID, tasks, storepb.TaskRun_DONE, common.SystemBotID, "")}(); err != nil {slog.Warn("failed to create issue comment", log.BBError(err))@@ -869,7 +869,7 @@ func (s *SchedulerV2) ListenTaskSkippedOrDone(ctx context.Context) {p := &storepb.IssueCommentPayload{Event: &storepb.IssueCommentPayload_StageEnd_{StageEnd: &storepb.IssueCommentPayload_StageEnd{- Stage: common.FormatStage(project.ResourceID, task.PipelineID, task.Environment),+ Stage: common.FormatStage(project.ResourceID, task.PipelineID, common.FormatStageID(task.Environment)),},},}diff --git a/frontend/src/utils/v1/issue/rollout.ts b/frontend/src/utils/v1/issue/rollout.tsindex 858d5faf20..0c9ebdac43 100644--- a/frontend/src/utils/v1/issue/rollout.ts+++ b/frontend/src/utils/v1/issue/rollout.ts@@ -145,9 +145,14 @@ export const findTaskByName = (rollout: Rollout | undefined,name: string): Task => {+ // Use task ID for comparison to handle legacy data with malformed stage IDs.+ const targetTaskUID = extractTaskUID(name);+ if (!targetTaskUID) {+ return unknownTask();+ }for (const stage of rollout?.stages ?? []) {for (const task of stage.tasks) {- if (task.name === name) {+ if (extractTaskUID(task.name) === targetTaskUID) {return task;}}@@ -159,7 +164,16 @@ export const findStageByName = (rollout: Rollout | undefined,name: string): Stage => {- return (rollout?.stages ?? []).find((s) => s.name === name) ?? unknownStage();+ // Use stage ID for comparison to handle legacy data with malformed stage IDs.+ const targetStageUID = extractStageUID(name);+ if (!targetStageUID) {+ return unknownStage();+ }+ return (+ (rollout?.stages ?? []).find(+ (s) => extractStageUID(s.name) === targetStageUID+ ) ?? unknownStage()+ );};export const extractSchemaVersionFromTask = (task: Task): string => {