8000 `flag_value` is not taken into account with `envvar` · Issue #2746 · pallets/click · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

flag_value is not taken into account with envvar #2746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dennisoehme opened this issue Jun 24, 2024 · 0 comments · Fixed by #2788
Closed

flag_value is not taken into account with envvar #2746

dennisoehme opened this issue Jun 24, 2024 · 0 comments · Fixed by #2788
Labels
Milestone

Comments

@dennisoehme
Copy link

When using the --debug option DEBUG environment variable in the sample command, the debug value is not correctly set (flag_value). It is expected to be either logging.DEBUG or None, but it seems to be getting the integer value directly from the environment variable.

Sample:

import logging
import os
import sys

import click


# Works as expected
# sys.argv = ['', '--debug']

# Does not work as expected
# os.environ['DEBUG'] = '1'

@click.command()
@click.option('--debug', is_flag=True, flag_value=logging.DEBUG, envvar='DEBUG')
def sample(debug):
    click.echo(f"DEBUG: {debug}")
    assert debug in [logging.DEBUG, None], f"Invalid debug value: {debug} - expected >{logging.DEBUG}< or None"


if __name__ == '__main__':
    sample()

There is no different in using os.environ or DEBUG=1 python cli.py.

DEBUG=8 python cli.py prints out: 8

Environment:

  • Python version: 3.12.4
  • Click version: 8.1.7
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2024
@AndreasBackx AndreasBackx added this to the 8.2.0 milestone Jan 12, 2025
@Rowlando13 Rowlando13 added the bug label May 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0