fix: dynamically report backend_host in terminal logs#6222
fix: dynamically report backend_host in terminal logs#6222Krishnachaitanyakc wants to merge 1 commit intoreflex-dev:mainfrom
Conversation
…oded 0.0.0.0 The notify_backend() function was hardcoding "0.0.0.0" as the backend host in the terminal log output, ignoring the backend_host value set in rxconfig.py or passed via --backend-host CLI argument. This change: - Adds an optional `host` parameter to notify_backend() that falls back to config.backend_host when not provided - Passes the resolved host from run_backend() and run_backend_prod() call sites so CLI --backend-host overrides are reflected in logs - Persists the resolved backend_host in the config (via _set_persistent) so it is available to notify_backend() even when called from the frontend thread in run_process_and_launch_url() Fixes reflex-dev#6165
Greptile SummaryThis PR fixes a long-standing cosmetic bug where Changes:
Issues found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as CLI / rxconfig
participant _run as _run() [reflex.py]
participant Config as Config [_set_persistent]
participant BackendThread as Backend Thread
participant FrontendThread as Frontend Thread
participant notify as notify_backend()
CLI->>_run: backend_host (CLI arg or config default)
_run->>Config: _set_persistent(backend_host) [if changed]
_run->>_run: get_config(reload=True)
_run->>BackendThread: run_backend(host, port, ...)
BackendThread->>notify: notify_backend(host) ✅ explicit host
_run->>FrontendThread: run_process_and_launch_url(...)
FrontendThread->>notify: notify_backend() [no host arg]
notify->>Config: get_config().backend_host [reads persisted value]
notify-->>FrontendThread: logs correct host ✅
|
| host: The backend host. If not provided, falls back to the config value. | ||
| """ | ||
| config = get_config() | ||
| effective_host = host or config.backend_host |
There was a problem hiding this comment.
Use
is not None instead of or for optional host
host or config.backend_host will silently discard an explicit empty string "" passed as host, falling back to the config value instead. Per project convention, you should check is not None to differentiate between "not supplied" and "explicitly empty":
| effective_host = host or config.backend_host | |
| effective_host = host if host is not None else config.backend_host |
Rule Used: When checking for the existence of a value that co... (source)
Learnt From
reflex-dev/flexgen#2444
Summary
notify_backend()which was hardcoding0.0.0.0as the backend host in terminal log output, ignoring thebackend_hostvalue configured inrxconfig.pyor passed via the--backend-hostCLI argument.hostparameter tonotify_backend()that falls back toconfig.backend_hostwhen not provided.run_backend()andrun_backend_prod()call sites so CLI--backend-hostoverrides are correctly reflected in logs.backend_hostin the config (via_set_persistent) so it is available tonotify_backend()even when called from the frontend thread inrun_process_and_launch_url().Closes #6165
Test plan
reflex runwith default config and verify log shows the correct default backend hostbackend_host="127.0.0.1"inrxconfig.py, run the app, and verify the log showshttp://127.0.0.1:<port>instead ofhttp://0.0.0.0:<port>--backend-host 192.168.1.1CLI flag and verify the log shows the CLI-specified hostreflex run --env prod) with a custombackend_hostand verify the log is correct