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 news/7947.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed console log level not being restored after `reflex export` completes, which caused `reflex deploy` to hide progress messages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Towncrier will ignore this fragment because root release notes are read from news/, not changes/; move it to news/7947.bugfix.md so the fix is included in the changelog.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At changes/7947.bugfix.md, line 1:

<comment>Towncrier will ignore this fragment because root release notes are read from `news/`, not `changes/`; move it to `news/7947.bugfix.md` so the fix is included in the changelog.</comment>

<file context>
@@ -0,0 +1 @@
+Fixed console log level not being restored after `reflex export` completes, which caused `reflex deploy` to hide progress messages.

</file context>

6 changes: 5 additions & 1 deletion reflex/utils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from reflex_base.config import get_config
from reflex_base.environment import environment
from reflex_base.utils import console
from reflex_base.utils import log as _log

from reflex.utils import build, exec, path_ops, prerequisites, telemetry

Expand Down Expand Up @@ -46,7 +47,9 @@ def export(
"""
config = get_config()

# Set the log level.
# Set the log level for the export, restoring the previous level afterward
# so that callers (e.g. `reflex deploy`) keep logging at their own level.
prev_log_level = _log.get_log_level()
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
console.set_log_level(loglevel)

start = time.monotonic()
Expand Down Expand Up @@ -105,6 +108,7 @@ def _time_phase(name: str) -> Iterator[None]:
detail = type(exc).__name__
raise
finally:
console.set_log_level(prev_log_level)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
telemetry.send(
"export",
status=status,
Expand Down
43 changes: 43 additions & 0 deletions tests/units/utils/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,46 @@ def require_release(*args, **kwargs):
export.export()

assert context.__exit__.call_args.args[:2] == (RuntimeError, error)


def test_export_restores_log_level_on_success(patched_export):
"""Console log level is restored after successful export."""
from reflex_base.utils import console, log as _log

initial_level = constants.LogLevel.INFO
console.set_log_level(initial_level)
assert _log.get_log_level() == initial_level

export.export(loglevel=constants.LogLevel.DEBUG, zipping=False, frontend=False, backend=False)

assert _log.get_log_level() == initial_level


def test_export_restores_log_level_on_failure(patched_export):
"""Console log level is restored even when export fails."""
from reflex_base.utils import console, log as _log

initial_level = constants.LogLevel.INFO
console.set_log_level(initial_level)

patched_export["get_compiled_app"].side_effect = RuntimeError("Test error")

assert _log.get_log_level() == initial_level

with pytest.raises(RuntimeError, match="Test error"):
export.export(loglevel=constants.LogLevel.DEBUG, zipping=False, frontend=False, backend=False)

assert _log.get_log_level() == initial_level


def test_export_preserves_log_level_when_none_specified(patched_export):
"""Console log level remains unchanged when loglevel=None."""
from reflex_base.utils import console, log as _log

initial_level = constants.LogLevel.WARNING
console.set_log_level(initial_level)
Comment on lines +311 to +312

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Tests leave logging settings behind

The new tests change the process-wide log level without restoring the level they found. The last test leaves _log_level and REFLEX_LOGLEVEL set to WARNING. The shared teardown calls _reset(), which restores neither value, so later tests and their subprocesses inherit this test's settings. Save and restore both values in a fixture.

assert _log.get_log_level() == initial_level

export.export(loglevel=None, zipping=False, frontend=False, backend=False)

assert _log.get_log_level() == initial_level
Loading