Skip to content

fix(hosting-cli): exit deploy when --envfile requires missing python-dotenv#6414

Open
BABTUNA wants to merge 1 commit intoreflex-dev:mainfrom
BABTUNA:fix-hosting-cli-envfile-importerror
Open

fix(hosting-cli): exit deploy when --envfile requires missing python-dotenv#6414
BABTUNA wants to merge 1 commit intoreflex-dev:mainfrom
BABTUNA:fix-hosting-cli-envfile-importerror

Conversation

@BABTUNA
Copy link
Copy Markdown
Contributor

@BABTUNA BABTUNA commented Apr 29, 2026

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

Fixes a deploy error path in reflex-hosting-cli when --envfile is provided but python-dotenv is not installed.

Before this change, deploy() logged an error in the ImportError branch but continued execution, which could lead to a deployment proceeding without envfile secrets.

After this change, deploy() exits immediately with click.exceptions.Exit(1) in that branch (matching existing behavior in v2/secrets.py).

Tests

Added regression test:

  • test_deploy_envfile_missing_python_dotenv_exits

The test verifies:

  • deploy() exits when dotenv import fails
  • export is not started
  • deployment is not created

Validation

  • uv run ruff check packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py tests/units/reflex_cli/v2/test_cli.py
  • uv run pytest tests/units/reflex_cli/v2/test_cli.py -q

Follow-up to #6369

@BABTUNA BABTUNA requested a review from a team as a code owner April 29, 2026 00:53
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR fixes a bug where deploy() would continue executing after logging an ImportError for python-dotenv when --envfile is provided, potentially starting an export and deployment without the expected environment variables. The fix adds raise click.exceptions.Exit(1) from None immediately after the error log, matching the existing pattern in v2/secrets.py, and includes a focused regression test.

Confidence Score: 5/5

This PR is safe to merge — it is a minimal, targeted bug fix with a focused regression test.

The change is a single line that corrects a clear fall-through bug: the missing raise after the error log. It matches the existing pattern in the codebase, the test correctly exercises the failure path, and there are no side-effects or regressions introduced.

No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py Single-line fix: adds raise click.exceptions.Exit(1) from None after the error log in the ImportError branch, preventing deployment from proceeding without envfile secrets.
tests/units/reflex_cli/v2/test_cli.py Adds test_deploy_envfile_missing_python_dotenv_exits which patches builtins.__import__ to simulate a missing dotenv package, then asserts that Exit is raised and neither export nor deployment are called.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[deploy called with --envfile] --> B{envfile set?}
    B -- No --> D[Continue: compile app]
    B -- Yes --> C{import dotenv}
    C -- Success --> C2[dotenv_values loaded] --> D
    C -- ImportError --> E[console.error message]
    E --> F["raise click.exceptions.Exit(1)\n(NEW: previously fell through)"]
    D --> G[export_fn]
    G --> H[create_deployment]
    H --> I[watch_deployment_status]
Loading

Reviews (1): Last reviewed commit: "fix(hosting-cli): exit deploy when envfi..." | Re-trigger Greptile

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing BABTUNA:fix-hosting-cli-envfile-importerror (6751bbc) with main (8f7ad9a)

Open in CodSpeed

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