Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/reflex-base/news/6815.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise a `ValueError` when an `EnvVar` is declared with a name that is not fully uppercase, so misnamed environment variables are caught at definition time.
6 changes: 6 additions & 0 deletions packages/reflex-base/src/reflex_base/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ def __init__(self, name: str, default: Any, type_: T) -> None:
name: The environment variable name.
default: The default value.
type_: The type of the value.

Raises:
ValueError: If the name is not fully uppercase.
"""
if not name.isupper():
msg = f"Environment variable name must be uppercase: {name!r}"
raise ValueError(msg)
Comment thread
greptile-apps[bot] marked this conversation as resolved.

@cubic-dev-ai cubic-dev-ai Bot Aug 4, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This validation turns a previously-accepted configuration into a hard runtime failure for any downstream user. EnvVar is a public class and is also constructed by the env_var descriptor from the declaring class's attribute name, so a user who extends EnvironmentVariables (or directly builds EnvVar) with a snake_case or mixed-case variable name β€” which was fully supported before β€” will now hit a ValueError the moment that attribute is accessed.

Consider whether a hard failure with no fallback is right for a public API. The repo's own guidance calls for a deprecation window when introducing breaking changes to downstream users (per AGENTS.md/CLAUDE.md). A gentler approach would be to warn during a deprecation period (e.g. console.deprecate) before enforcing the error, or to scope the enforcement so it doesn't reject names that are legitimately intended to be read as-is.

Prompt for AI agents
Check if this issue is valid β€” if so, understand the root cause and fix it. At packages/reflex-base/src/reflex_base/environment.py, line 414:

<comment>This validation turns a previously-accepted configuration into a hard runtime failure for any downstream user. EnvVar is a public class and is also constructed by the env_var descriptor from the declaring class's attribute name, so a user who extends EnvironmentVariables (or directly builds EnvVar) with a snake_case or mixed-case variable name β€” which was fully supported before β€” will now hit a ValueError the moment that attribute is accessed.

Consider whether a hard failure with no fallback is right for a public API. The repo's own guidance calls for a deprecation window when introducing breaking changes to downstream users (per AGENTS.md/CLAUDE.md). A gentler approach would be to warn during a deprecation period (e.g. console.deprecate) before enforcing the error, or to scope the enforcement so it doesn't reject names that are legitimately intended to be read as-is.</comment>

<file context>
@@ -405,7 +405,13 @@ def __init__(self, name: str, default: Any, type_: T) -> None:
         """
+        if not name.isupper():
+            msg = f"Environment variable name must be uppercase: {name!r}"
+            raise ValueError(msg)
         self.name = name
         self.default = default
</file context>
Fix with cubic

self.name = name
self.default = default
self.type_ = type_
Expand Down
21 changes: 21 additions & 0 deletions tests/units/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,27 @@ def test_set_list_value(self):
del os.environ["TEST_VAR"]


@pytest.mark.parametrize("name", ["test_var", "Test_Var", "tEST_VAR", "reflex_use_npm"])
def test_env_var_name_not_uppercase_raises(name):
"""Test that a non-uppercase environment variable name is rejected.

Args:
name: The invalid environment variable name.
"""
with pytest.raises(ValueError, match="must be uppercase"):
EnvVar(name, "default", str)


@pytest.mark.parametrize("name", ["TEST_VAR", "__INTERNAL_VAR", "VAR_2"])
def test_env_var_name_uppercase_accepted(name):
"""Test that fully uppercase environment variable names are accepted.

Args:
name: The valid environment variable name.
"""
assert EnvVar(name, "default", str).name == name


class TestEnvVarDescriptor:
"""Test the env_var descriptor."""

Expand Down
Loading