Skip to content

Fix competitions pages subcommand parsing - #1258

Open
Nghiauet wants to merge 2 commits into
Kaggle:mainfrom
Nghiauet:fix-competitions-pages
Open

Nghiauet wants to merge 2 commits into
Kaggle:mainfrom
Nghiauet:fix-competitions-pages

Conversation

@Nghiauet

Copy link
Copy Markdown

Summary

kaggle competitions pages <competition> is currently unusable. pages <comp>, pages list <comp>, and the documented pages create <comp> ... all fail with error: argument command: invalid choice: '<comp>'. Only the deprecated -c/--competition flag works.

Cause

The competitions pages parser attached an optional competition positional (via the shared options parent) on the same parser that also registers the {list,create,update,delete} subparsers. argparse routes the first positional token to the subparsers action, so a competition slug is parsed as a subcommand name and rejected.

Fix

  • Remove the competition positional from the shared options parent; re-add it only on the list subparser.
  • Add a subparsers action that routes a bare <competition> token to list <competition>, while preserving pages-level options (e.g. --content before the slug).
  • Keep the deprecated -c/--competition working unchanged.

Tests

Added parser-level tests in tests/unit/test_cli_competitions.py covering the bare positional, an option before the positional, the no-args default, and the list/create/update/delete positional forms.

  • pytest tests/unit/test_cli_competitions.py → 69 passed
  • full tests/unit → 1535 passed
  • black --line-length 120 --check clean; mypy src/kaggle/cli.py → Success

`kaggle competitions pages <competition>` and the explicit forms
`pages list|create|update|delete <competition>` all failed with
"argument command: invalid choice: '<competition>'". The `pages` parser
carried an optional `competition` positional alongside its
{list,create,update,delete} subcommands; argparse hands the first token
to the subparsers action, so the competition slug was parsed as a
(non-existent) subcommand. Only the hidden `-c` alias worked.

Move the `competition` positional onto the `list` subparser and route a
bare `pages <competition>` to `list` via a small _SubParsersAction
subclass, so every documented form works while the deprecated `-c`
option is unchanged. Add parser-level tests for the positional forms.
@google-cla

google-cla Bot commented Nov 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Comment thread src/kaggle/cli.py
@@ -521,11 +552,17 @@ def parse_competitions(subparsers) -> None:
help=Help.command_competitions_pages,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small optional thing: since the competition positional moved to the list subparser, kaggle competitions pages -h no longer shows it. The usage line is now just {list,create,update,delete} ..., so there's no hint that pages <competition> works. Maybe add a short description here? Totally fine to skip if you think it's not worth it.

Suggested change
help=Help.command_competitions_pages,
help=Help.command_competitions_pages,
description="pages <competition> is shorthand for pages list <competition>.",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! Applied in f82140f, so kaggle competitions pages -h now shows:

pages <competition> is shorthand for pages list <competition>.

@sridipbasu sridipbasu added the bug Something isn't working label Nov 25, 2026
Moving the competition positional onto the list subparser removed it from
the pages usage line. Add a parser description so pages -h still shows
that pages <competition> is shorthand for pages list <competition>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants