fix FLASK_DEBUG env var ignored with click 8.4.0 (#6025)
In click 8.4.0, `get_parameter_source` returns `None` during eager callbacks instead of `ParameterSource.DEFAULT`. The guard in `_set_debug` only checked for `source is not None`, so it fell through and overwrote the user's `FLASK_DEBUG=1` env var with `"0"`. Treat `source is None` the same as `DEFAULT` — return early without overwriting the env var. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
954f5684e4
commit
0d2d49e779
2 changed files with 25 additions and 1 deletions
|
|
@ -470,7 +470,7 @@ def _set_debug(ctx: click.Context, param: click.Option, value: bool) -> bool | N
|
|||
# that, let debug be set by env in that case.
|
||||
source = ctx.get_parameter_source(param.name)
|
||||
|
||||
if source is not None and source in (
|
||||
if source is None or source in (
|
||||
ParameterSource.DEFAULT,
|
||||
ParameterSource.DEFAULT_MAP,
|
||||
):
|
||||
|
|
|
|||
|
|
@ -382,6 +382,30 @@ def test_flaskgroup_debug(runner, set_debug_flag):
|
|||
assert result.output == f"{not set_debug_flag}\n"
|
||||
|
||||
|
||||
def test_flaskgroup_debug_env(monkeypatch, runner):
|
||||
"""FLASK_DEBUG=1 env var should not be overwritten when --debug is not
|
||||
explicitly passed. Regression test for click 8.4.0 where
|
||||
get_parameter_source returns None during eager callbacks.
|
||||
"""
|
||||
monkeypatch.setenv("FLASK_DEBUG", "1")
|
||||
|
||||
def create_app():
|
||||
app = Flask("flaskgroup")
|
||||
return app
|
||||
|
||||
@click.group(cls=FlaskGroup, create_app=create_app)
|
||||
def cli(**params):
|
||||
pass
|
||||
|
||||
@cli.command()
|
||||
def test():
|
||||
click.echo(os.environ.get("FLASK_DEBUG"))
|
||||
|
||||
result = runner.invoke(cli, ["test"])
|
||||
assert result.exit_code == 0
|
||||
assert result.output.strip() == "1"
|
||||
|
||||
|
||||
def test_flaskgroup_nested(app, runner):
|
||||
cli = click.Group("cli")
|
||||
flask_group = FlaskGroup(name="flask", create_app=lambda: app)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue