diff --git a/services/cd-service/pkg/repository/repository.go b/services/cd-service/pkg/repository/repository.go index 4d9fa6327..99cf9cda5 100644 --- a/services/cd-service/pkg/repository/repository.go +++ b/services/cd-service/pkg/repository/repository.go @@ -2079,6 +2079,9 @@ func (s *State) GetEnvironmentApplicationsFromDB(ctx context.Context, transactio if err != nil { return nil, err } + if envInfo == nil { + return nil, fmt.Errorf("environment %s not found", environment) + } if envInfo.Applications == nil { return make([]string, 0), nil } diff --git a/services/cd-service/pkg/repository/transformer.go b/services/cd-service/pkg/repository/transformer.go index e4d4a613d..2cbfd7cbe 100644 --- a/services/cd-service/pkg/repository/transformer.go +++ b/services/cd-service/pkg/repository/transformer.go @@ -3388,7 +3388,7 @@ func getOverrideVersions(ctx context.Context, transaction *sql.Tx, commitHash, u return resp, nil } -func (c *ReleaseTrain) getUpstreamLatestApp(ctx context.Context, transaction *sql.Tx, upstreamLatest bool, state *State, upstreamEnvName, source, commitHash string) (apps []string, appVersions []Overview, err error) { +func (c *ReleaseTrain) getUpstreamLatestApp(ctx context.Context, transaction *sql.Tx, upstreamLatest bool, state *State, upstreamEnvName, source, commitHash string, targetEnv string) (apps []string, appVersions []Overview, err error) { if commitHash != "" { appVersions, err := getOverrideVersions(ctx, transaction, c.CommitHash, upstreamEnvName, c.Repo) if err != nil { @@ -3409,7 +3409,9 @@ func (c *ReleaseTrain) getUpstreamLatestApp(ctx context.Context, transaction *sq return apps, appVersions, nil } if upstreamLatest { - apps, err = state.GetApplications(ctx, transaction) + // For "upstreamlatest" we cannot get the source environment, because it's not a real environment + // but since we only care about the names of the apps, we can just get the apps for the target env. + apps, err = state.GetEnvironmentApplications(ctx, transaction, targetEnv) if err != nil { return nil, nil, grpc.PublicError(ctx, fmt.Errorf("could not get all applications for %q: %w", source, err)) } @@ -3710,7 +3712,7 @@ func (c *envReleaseTrain) prognosis( source = "latest" } - apps, overrideVersions, err := c.Parent.getUpstreamLatestApp(ctx, transaction, upstreamLatest, state, upstreamEnvName, source, c.Parent.CommitHash) + apps, overrideVersions, err := c.Parent.getUpstreamLatestApp(ctx, transaction, upstreamLatest, state, upstreamEnvName, source, c.Parent.CommitHash, c.Env) if err != nil { return ReleaseTrainEnvironmentPrognosis{ SkipCause: nil,