#Uvicorn and root-path

1 messages · Page 1 of 1 (latest)

woven bobcat
#

I saw that https://github.com/litestar-org/litestar/issues/2998 was closed but I do think Litestar is affected. At least, maybe I need to do something different to work around it.

Once Uvicorn is upgraded to v0.26 or beyond, the path query type gets the value of --root-path prepended to it. This is new behavior that is breaking some of my Litestar apps if I go past Uvicorn 0.25. I can update my code to accommodate but, since this is new behavior, I wanted to confirm this new behavior is expected.

MCVE:

Uvicorn <0.26:

  1. uvicorn mcve:app --root-path /test
  2. curl http://localhost:8000/myPath -> "path: /myPath"

Uvicorn >=0.26:

  1. uvicorn mcve:app --root-path /test
  2. curl http://localhost:8000/myPath -> "path: /test/myPath"
from pathlib import Path

from litestar import Litestar
from litestar.handlers import get

@get(path=["/", "/{path:path}"], sync_to_thread=False)
def pathfinder(path: Path | None) -> str:
    return f"path: {path}"


app = Litestar(route_handlers=[pathfinder], debug=True)

Cheers!

misty hullBOT
lyric oxideBOT
#
Notes for Uvicorn and root-path
At your assistance

@woven bobcat

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.

snow gazelle
#

Oh, interesting

#

Thanks for reporting this

#

That seems to be a different error case than initially assumed

#

Would you mind opening a seperate issue for this with your example attached?

woven bobcat
#

@snow gazelle certainly!

misty hullBOT
#

Description

Once Uvicorn is upgraded to v0.26 or beyond, any path parameters type gets the value of --root-path prepended to them.

URL to code causing the issue

No response

MCVE

from pathlib import Path

from litestar import Litestar
from litestar.handlers import get

@get(path=["/", "/{path:path}"], sync_to_thread=False)
def pathfinder(path: Path | None) -> str:
    return f"path: {path}"

app = Litestar(route_handlers=[pathfinder], debug=True)

Steps to reproduce

Uvicorn <0.26:
1. uvicorn mcve:app --root-path /test
2. curl http://localhost:8000/myPath -> "path: /myPath"

Uvicorn >=0.26:
1. uvicorn mcve:app --root-path /test
2. curl http://localhost:8000/myPath -> "path: /test/myPath"

Screenshots

No response

Logs

No response

Litestar Version

2.5.2

Platform

  • ✅ Linux
  • ◻️ Mac
  • ◻️ Windows
  • ◻️ Other (Please specify in the description above)

[!NOTE]
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Labels

Bug :bug:

snow gazelle
misty hullBOT
snow gazelle
#

@woven bobcat the fix for this has been released