Skip to content

Fix allow_dash for Path parameters - #2016

Open
anubhavlal07 wants to merge 2 commits into
fastapi:masterfrom
anubhavlal07:fix/path-allow-dash
Open

anubhavlal07 wants to merge 2 commits into
fastapi:masterfrom
anubhavlal07:fix/path-allow-dash

Conversation

@anubhavlal07

Copy link
Copy Markdown

A Path option with allow_dash=True rejects - when it also sets resolve_path=True (or anything else that turns the value into a Path before the dash check). coerce_cli_path compares rv against b"-" and "-", but by that point rv can be Path("-"), which equals neither, so the dash is treated as a real path and fails the exists=True check:

@app.command()
def main(config: Path = typer.Option(..., exists=True, resolve_path=True, allow_dash=True)):
    ...
$ app --config -
Invalid value for '--config': path '-' does not exist.

The check now compares os.fspath(rv), so str, bytes and Path values are all recognised as the dash. Added test_coercion_path_allow_dash, which fails before this change and passes after it.

@svlandeg svlandeg self-assigned this Nov 12, 2026
@svlandeg svlandeg added the bug Something isn't working label Nov 12, 2026
@svlandeg

Copy link
Copy Markdown
Member

Thanks for the report @anubhavlal07 ! I'll look into this.

This branch has not been deployed

No deployments
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