Skip to content

Fix --reload interpreting 'serve' command as a file argument#2646

Merged
simonw merged 2 commits intosimonw:mainfrom
danielalanbates:fix/issue-2123
Feb 26, 2026
Merged

Fix --reload interpreting 'serve' command as a file argument#2646
simonw merged 2 commits intosimonw:mainfrom
danielalanbates:fix/issue-2123

Conversation

@danielalanbates
Copy link
Contributor

@danielalanbates danielalanbates commented Feb 20, 2026

Summary

Fixes #2123. When datasette serve --reload test_db is run, the serve word is interpreted as a file argument, causing Error: Invalid value for '[FILES]...': Path 'serve' does not exist.

Root cause

hupper.start_reloader("datasette.cli.serve") tells hupper to call the serve Click command function directly in the worker process. Since this bypasses the cli group (which uses click_default_group.DefaultGroup), Click parses sys.argv[1:] without recognizing serve as a subcommand — treating it as a positional file argument instead.

Fix

Change the worker path from "datasette.cli.serve" to "datasette.cli.cli" so the worker process enters through the CLI group, which properly dispatches serve as a subcommand.

This also handles the case where serve is omitted (datasette --reload test_db), since DefaultGroup correctly falls back to the default serve command.

Test plan

  • datasette serve --reload test_db no longer treats serve as a file
  • datasette --reload test_db (implicit serve) continues to work
  • Reload-on-file-change behavior is preserved since hupper detects the worker environment and returns a proxy on subsequent invocations

This PR was created with the assistance of Claude Opus 4.6 by Anthropic. Happy to make any adjustments!


📚 Documentation preview 📚: https://datasette--2646.org.readthedocs.build/en/2646/

When hupper spawns the worker process, it calls the function specified by
worker_path directly. Using "datasette.cli.serve" causes Click to parse
sys.argv without going through the CLI group, so the literal word "serve"
from the original command gets treated as a positional file argument.

Change the worker path to "datasette.cli.cli" so the worker process goes
through the Click group dispatcher, which properly recognizes "serve" as
a subcommand and strips it from the argument list.

Closes simonw#2123

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@simonw
Copy link
Owner

simonw commented Feb 26, 2026

Thanks for catching this.

@simonw simonw merged commit 2bc1dd2 into simonw:main Feb 26, 2026
1 check was pending
simonw added a commit that referenced this pull request Feb 26, 2026
@danielalanbates
Copy link
Contributor Author

Thank you for the review! Glad it helps. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datasette serve when invoked with --reload interprets the serve command as a file

2 participants