Skip to content

fix: getEnvironmentsToBuild queried a relation removed in phase 1 - #231

Open
vigneshrajsb wants to merge 1 commit into
mainfrom
fix/environments-to-build-unknown-relation
Open

fix: getEnvironmentsToBuild queried a relation removed in phase 1#231
vigneshrajsb wants to merge 1 commit into
mainfrom
fix/environments-to-build-unknown-relation

Conversation

@vigneshrajsb

Copy link
Copy Markdown
Contributor

Summary

Phase 1 of the dead-code cleanup (#228) removed Environment.relationMappings.services along with the rest of the legacy DB-config path, but left one call site behind in getEnvironmentsToBuild:

Environment.find().withGraphJoined('services').where('services.repositoryId', repositoryId)

Objection throws UnknownRelationError: services when this runs.

Impact

Latent, not loud. The branch only executes when environmentId is null — i.e. a repository whose defaultEnvId is not set (github.ts passes repository?.defaultEnvId straight through to createBuildAndDeploys). Repositories onboarded normally have a defaultEnvId, which is why production has been quiet since #228 merged.

Fix

That else branch was the DB-service-based environment lookup — "find the environments that own a service belonging to this repo". Under YAML config a repository's environment is its defaultEnvId, so the branch is meaningless now and is removed rather than repaired. Returning [] is exactly what the caller already handles:

if (!environments.length) {
  getLogger().debug('Build: no matching environments');
  return;
}

Also stops pushing a possibly-undefined findOne() result into the array, which would otherwise surface later as an undefined element during environments.map(...).

Testing

  • New BuildService getEnvironmentsToBuild suite, verified to fail on the previous implementation and pass on this one. The Environment.find mock throws if called, and the missing-environment case uses toStrictEqual so [undefined] cannot pass as [].
  • Full suite: 3768 passed. lint clean. ts-check: 291 errors on main, 291 on this branch — zero new.

Found while re-verifying scope for phase 2 of the cleanup.

The dead-code cleanup (#228) removed Environment.relationMappings.services
along with the rest of the legacy DB-config path, but left this call site:

    Environment.find().withGraphJoined('services').where('services.repositoryId', ...)

Objection throws UnknownRelationError: services when it runs. It is reached
from createBuildAndDeploys -> getEnvironmentsToBuild whenever environmentId
is null, i.e. a repository whose defaultEnvId is not set (github.ts passes
repository?.defaultEnvId straight through), so it has been latent rather
than loud.

That else-branch was the DB-service-based environment lookup: "find the
environments that own a service belonging to this repo". With YAML config a
repository's environment is its defaultEnvId, so the branch has no meaning
anymore and is removed rather than repaired. Returning an empty array is
what the caller already expects - it logs "no matching environments" and
returns.

Also stops pushing a possibly-undefined findOne() result into the array,
which would surface later as an undefined element during environments.map().

Adds regression coverage that fails on the previous implementation: the
Environment.find mock throws if called, and the missing-environment case
uses toStrictEqual so [undefined] cannot pass as [].
@vigneshrajsb
vigneshrajsb requested a review from a team as a code owner July 27, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant