Skip to content

fix(serve): coerce --reload CLI string to bool via env()#110

Open
bedus-creation wants to merge 2 commits into
mainfrom
fix/serve-reload-bool-parse
Open

fix(serve): coerce --reload CLI string to bool via env()#110
bedus-creation wants to merge 2 commits into
mainfrom
fix/serve-reload-bool-parse

Conversation

@bedus-creation

Copy link
Copy Markdown
Contributor

Summary

  • Bug: --reload=False passed on the CLI was forwarded to uvicorn as the string "False". Uvicorn treats any non-empty string as truthy, so --reload=False actually enabled reloading instead of disabling it.
  • Fix: Import env as _env from fastapi_startkit.environment and coerce the CLI string with _env(cli_reload, cli_reload) before passing it to uvicorn. This maps "False"/"false"False and "True"/"true"True using the existing casting logic in env().

Files changed

  • fastapi_startkit/src/fastapi_startkit/fastapi/commands/serve_command.py — import env as _env, replace one-liner with two-liner that coerces the string
  • fastapi_startkit/tests/fastapi/test_serve_command.py — new test file

Test plan

  • All 37 fastapi tests pass (uv run pytest tests/fastapi/ -v)
  • test_reload_none_falls_back_to_cfg_reload_trueNone falls back to config True
  • test_reload_none_falls_back_to_cfg_reload_falseNone falls back to config False
  • test_reload_string_False_becomes_bool_false"False"False
  • test_reload_string_True_becomes_bool_true"True"True
  • test_reload_string_false_lowercase_becomes_bool_false"false"False

🤖 Generated with Claude Code

bedus-creation and others added 2 commits June 10, 2026 16:35
When Cleo passes --reload=False/True as a string, the old code forwarded
the raw string to uvicorn, which treated any non-empty string as truthy.
Now the string is coerced with _env(cli_reload, cli_reload) from
fastapi_startkit.environment, which maps "False"/"false" → False and
"True"/"true" → True before passing the value to uvicorn.

Adds tests/fastapi/test_serve_command.py covering:
- None option falls back to fastapi config value
- "False" → False
- "True" → True
- "false" (lowercase) → False

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace hand-rolled unittest.mock approach (patching option() and calling
handle() directly) with CommandTester.execute() so Cleo drives the full
command path naturally. External dependencies (uvicorn.run, Config.get,
is_app_exist) are still patched; option() is no longer patched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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