pallets / pallets/click

Invoking a command does not fail on missing arguments

Open
#2,801 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
17.7k
Forks
2.3k
Avg merge
1d 30m
Merged PRs (30d)
18

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal Python example in the issue and trace Click's Context.invoke argument handling. Check the existing invocation and argument-validation entry points and related tests, if present. Done means the behavior for a required argument invoked without a value is explicitly defined and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.