click icon indicating copy to clipboard operation
click copied to clipboard

Invoking a command does not fail on missing arguments

Open oeko2002 opened this issue 1 year ago • 1 comments

If I invoke a command with an required argument (nargs=1) from within another one without passing the argument it still works. None is passed as default, although I do no set some. If I invoke the callback I get the expected exception.

Short example

import click

@click.group()
def group():
    pass

@group.command()
@click.argument("arg", nargs=1, required=True)
def withparam(arg):
    print(
        f"INVOKED with argument {arg}"
    )

@group.command()
def withoutparam():
    print(f"RUNNING without params")
    click.get_current_context().invoke(withparam)

if __name__ == "__main__":
    group()

Result is:

> python test.py withoutparam
RUNNING without params
INVOKED with argument None

Is this intended?

Environment:

  • Python version: 3.13
  • Click version: 8.1.7

oeko2002 avatar Nov 07 '24 13:11 oeko2002

This is intended and somewhat documented in the options section. I will add it to the arguments section explicitly.

Rowlando13 avatar Apr 06 '25 00:04 Rowlando13