Skip to content

Commit defca45

Browse files
authored
Handle REFLEX_ENV_FILE at init time (#5349)
This was missed when env vars were renamed to use the REFLEX_ prefix Also fixes up a test miss where redis tests were skipped even when providing REFLEX_REDIS_URL.
1 parent 71fa6a9 commit defca45

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

reflex/config.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,27 @@ def _load_dotenv_from_str(env_files: str) -> None:
6969
load_dotenv(env_file_path, override=True)
7070

7171

72+
def _load_dotenv_from_env():
73+
"""Load environment variables from paths specified in REFLEX_ENV_FILE."""
74+
show_deprecation = False
75+
env_env_file = os.environ.get("REFLEX_ENV_FILE")
76+
if not env_env_file:
77+
env_env_file = os.environ.get("ENV_FILE")
78+
if env_env_file:
79+
show_deprecation = True
80+
if show_deprecation:
81+
console.deprecate(
82+
"Usage of deprecated ENV_FILE env var detected.",
83+
reason="Prefer `REFLEX_` prefix when setting env vars.",
84+
deprecation_version="0.7.13",
85+
removal_version="0.8.0",
86+
)
87+
if env_env_file:
88+
_load_dotenv_from_str(env_env_file)
89+
90+
7291
# Load the env files at import time if they are set in the ENV_FILE environment variable.
73-
if env_files := os.getenv("ENV_FILE"):
74-
_load_dotenv_from_str(env_files)
92+
_load_dotenv_from_env()
7593

7694

7795
class DBConfig(Base):

tests/units/test_state.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,7 +3321,10 @@ async def test_setvar_async_setter():
33213321
TestState.setvar("asynctest", 42)
33223322

33233323

3324-
@pytest.mark.skipif("REDIS_URL" not in os.environ, reason="Test requires redis")
3324+
@pytest.mark.skipif(
3325+
"REDIS_URL" not in os.environ and "REFLEX_REDIS_URL" not in os.environ,
3326+
reason="Test requires redis",
3327+
)
33253328
@pytest.mark.parametrize(
33263329
"expiration_kwargs, expected_values",
33273330
[
@@ -3394,7 +3397,10 @@ def test_redis_state_manager_config_knobs(tmp_path, expiration_kwargs, expected_
33943397
assert state_manager.lock_warning_threshold == expected_values[2] # pyright: ignore [reportAttributeAccessIssue]
33953398

33963399

3397-
@pytest.mark.skipif("REDIS_URL" not in os.environ, reason="Test requires redis")
3400+
@pytest.mark.skipif(
3401+
"REDIS_URL" not in os.environ and "REFLEX_REDIS_URL" not in os.environ,
3402+
reason="Test requires redis",
3403+
)
33983404
@pytest.mark.parametrize(
33993405
"redis_lock_expiration, redis_lock_warning_threshold",
34003406
[

0 commit comments

Comments
 (0)