Skip to content

fix(cli): prioritize LIGHTDASH_PROJECT over active previews - #28921

Merged
joaoviana merged 2 commits into
mainfrom
linear/prod-11044-ld-runner-prod-11044-3d80b4378ba7
Sep 11, 2026
Merged

fix(cli): prioritize LIGHTDASH_PROJECT over active previews#28921
joaoviana merged 2 commits into
mainfrom
linear/prod-11044-ld-runner-prod-11044-3d80b4378ba7

Conversation

@joaoviana

@joaoviana joaoviana commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Problem

LIGHTDASH_PROJECT is documented as "overrides the project UUID in the config file, useful when you want to target a specific project without using --project", but it only filled the production slot of the config. With a preview still recorded locally, non-interactive runs picked the preview anyway, so a CI deploy with LIGHTDASH_PROJECT set silently landed in a stale preview project for four days (customer report in PROD-11044).

Fix

Project selection now resolves --project > LIGHTDASH_PROJECT > active preview > saved project, in both interactive and non-interactive runs, through one helper (resolveProjectOverride) shared by selectProject (deploy, download, upload, slug-update, apps) and the rename command's separate path.

When the environment variable overrides an active preview the CLI warns instead of switching silently:

Using project <uuid> from LIGHTDASH_PROJECT; active preview "my-feature" ignored.
Pass --project <preview uuid> or unset LIGHTDASH_PROJECT to target the preview.

The stored preview is validated before warning, so a preview that was already deleted is cleared from the config rather than reported. The saved preview is never cleared by the override itself; stop-preview and set-project keep their meaning.

getConfig also stops returning the cached project name when the env var points at a different project, so logs no longer print a stale name next to the overridden UUID.

Design discussion

The mental model raised in review ("once you start a preview, later commands target it until set-project or stop-preview") still holds for the config-file case: with no override set, an active preview is the non-interactive default and interactive runs prompt. The env var is treated as an explicit instruction, the same category as --project, because that is what the docs already promise and what every CI template relies on. The warning covers the local-dev case of a LIGHTDASH_PROJECT left in a shell profile or .env.

Regression analysis

  • Official cli-actions templates (deploy.yml, start-preview.yml, close-preview.yml, lightdash-validate.yml) all set LIGHTDASH_PROJECT to the production project. start-preview and stop-preview do not go through project selection (they use the env project as the upstream to copy content from, and the preview by name), so preview workflows are unchanged. deploy and validate already targeted the env project on a fresh runner; on a runner with persisted CLI state they now do too, which is the fix.
  • lightdash validate never auto-selected a preview (only via --preview), so its behaviour is unchanged.
  • --project behaviour is unchanged: no warning, no extra API call.
  • Behaviour change only when all three hold: no --project, LIGHTDASH_PROJECT set, and a preview recorded in the local config. Previously: preview (non-interactive) or prompt (interactive). Now: env project plus a warning naming the ignored preview.
  • One extra GET /api/v1/projects/:uuid in that same case, to validate the preview before warning.

Verification

  • pnpm -F cli test: 57 files, 706 tests pass, including new coverage for env-over-preview in both modes, the warning text, no warning without a preview or when the env var names the preview itself, deleted-preview cleanup, slug resolution from the env var, --project precedence, empty env var keeping the preview default, and rename targeting.
  • pnpm -F cli typecheck, pnpm -F cli lint, oxfmt clean.
  • Rebased on main (2.194.1).

Docs follow-up: lightdash/mintlify-docs#1243 updates the CLI reference and the preview guide.

Closes: PROD-11044
Closes #28836

🤖 Generated with Claude Code

https://claude.ai/code/session_01DhkPTUcayHNKi2jkr3bgKs

@linear-code

linear-code Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

PROD-11044

@rainbow-machine

rainbow-machine Bot commented Sep 9, 2026

Copy link
Copy Markdown

🌈 The environment for this PR was shut down when it closed. Reopening the PR brings it back at the same URL.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

🧪 Test Selection

✅ Tests that will run

Test Description
Preview Environment Deploys a preview environment for testing
CLI Tests Runs CLI integration and dbt version tests

⏭️ Tests skipped (no relevant file changes detected)

Test How to trigger manually
Frontend E2E Tests Add test-frontend to PR description
Backend API Tests Add test-backend to PR description
Timezone Tests Add test-timezone to PR description

Tip: Add test-all to your PR description to run all tests.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Your preview environment pr-28921 has been deployed.

Preview environment endpoints are available at:

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Preview Environment

🌐 URL: https://lightdash-preview-pr-28921.lightdash.okteto.dev

📋 Logs: View in GCP Console

🔧 SSH: ./scripts/okteto-ssh.sh 28921

joaoviana and others added 2 commits September 11, 2026 09:24
Co-authored-by: joao@lightdash.com <joao@lightdash.com>
Share the override resolution between selectProject and rename so both
paths apply --project > LIGHTDASH_PROJECT > active preview, and tell the
user which preview was skipped when the environment variable wins. A
preview that no longer exists is cleared from the config instead of
being reported.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DhkPTUcayHNKi2jkr3bgKs
@joaoviana
joaoviana force-pushed the linear/prod-11044-ld-runner-prod-11044-3d80b4378ba7 branch from d9c0445 to 1fd75ab Compare September 11, 2026 08:30
@joaoviana
joaoviana marked this pull request as ready for review September 11, 2026 08:35
@joaoviana
joaoviana merged commit cf08d22 into main Sep 11, 2026
55 of 57 checks passed
@joaoviana
joaoviana deleted the linear/prod-11044-ld-runner-prod-11044-3d80b4378ba7 branch September 11, 2026 08:51
lightdash-bot pushed a commit that referenced this pull request Sep 11, 2026
# [2.195.0](2.194.2...2.195.0) (2026-09-11)

### Bug Fixes

* **cli:** prioritize LIGHTDASH_PROJECT over active previews ([#28921](#28921)) ([cf08d22](cf08d22))

### Features

* **roadmap:** remove organization-roadmap flag, gate on valid license ([#29016](#29016)) ([03e1bf5](03e1bf5))
@lightdash-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 2.195.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LIGHTDASH_PROJECT does not override an active preview project in non-interactive CLI runs

2 participants