Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not overwrite "path" and "root_path" scope keys #2352

Merged
merged 3 commits into from
Dec 1, 2023
Merged

Conversation

Kludex
Copy link
Sponsor Member

@Kludex Kludex commented Nov 29, 2023

@Kludex Kludex added this to the Version 1.0 milestone Nov 29, 2023
@Kludex Kludex requested review from abersheeran and a team November 30, 2023 13:09
@Kludex Kludex marked this pull request as ready for review November 30, 2023 13:09
@Kludex
Copy link
Sponsor Member Author

Kludex commented Nov 30, 2023

I'm going to try to make this PR cleaner, but it already solves the problem.

@Kludex Kludex changed the title Do not overwrite "path" and "root_path" scope keys Do not overwrite "path" and "root_path" scope keys Nov 30, 2023
Copy link
Member

@frankie567 frankie567 left a comment

Choose a reason for hiding this comment

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

Apart from my question above, LGTM! You have filled the holes I left in my previous PR :)

Still not convinced about the naming current_root_path and current_path, but that's minor 😄 Suggestion (not ideal): route_root_path / route_path.

path_params = dict(scope.get("path_params", {}))
path_params.update(matched_params)
root_path = scope.get("root_path", "")
child_scope = {
"path_params": path_params,
"app_root_path": scope.get("app_root_path", root_path),
"root_path": root_path + matched_path,
"path": remaining_path,
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to keep the original root_path and path in the child scope?

Copy link
Sponsor Member Author

@Kludex Kludex Dec 1, 2023

Choose a reason for hiding this comment

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

Aren't they always there anyway? Those lines were just modifying them, no?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you're right. My point was if we were using this child_scope as the new scope for inner routers, but it seems actually that it's always merged with the root scope.

@Kludex Kludex mentioned this pull request Dec 1, 2023
4 tasks
@Kludex
Copy link
Sponsor Member Author

Kludex commented Dec 1, 2023

@encode/maintainers can someone review this, please?

Copy link
Member

@abersheeran abersheeran left a comment

Choose a reason for hiding this comment

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

It looks very nice, I like the regular expressions here.

@Kludex Kludex merged commit e8f0dcd into master Dec 1, 2023
5 checks passed
@Kludex Kludex deleted the fix-path-on-mount branch December 1, 2023 12:55
maartenbreddels added a commit to widgetti/solara that referenced this pull request Dec 5, 2023
path now includes root_path so we need a different way to
remove it. It seems like route_root_path gives this information.

See encode/starlette#2361
encode/starlette#2352
encode/starlette#1336
maartenbreddels added a commit to widgetti/solara that referenced this pull request Dec 8, 2023
path now includes root_path so we need a different way to
remove it. It seems like route_root_path gives this information.

See encode/starlette#2361
encode/starlette#2352
encode/starlette#1336
RobbeSneyders pushed a commit to spec-first/connexion that referenced this pull request Dec 29, 2023
Fixes the change in behaviour in starlette v0.33 via PR
[#2352](encode/starlette#2352)
edoakes added a commit to ray-project/ray that referenced this pull request Feb 12, 2024
FastAPI has fixed the broken starlette interaction in 0.109.2: https://fastapi.tiangolo.com/release-notes/#01092

Starlette handling of root_path has changed in 0.33.0: encode/starlette#2352. Prior to this, it was incorrectly stripping the root_path from the path field (which we need to mirror). Added compatibility logic to handle both of these.

---------

Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Co-authored-by: Lonnie Liu <95255098+aslonnie@users.noreply.github.com>
tterrysun pushed a commit to tterrysun/ray that referenced this pull request Feb 14, 2024
FastAPI has fixed the broken starlette interaction in 0.109.2: https://fastapi.tiangolo.com/release-notes/#01092

Starlette handling of root_path has changed in 0.33.0: encode/starlette#2352. Prior to this, it was incorrectly stripping the root_path from the path field (which we need to mirror). Added compatibility logic to handle both of these.

---------

Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Co-authored-by: Lonnie Liu <95255098+aslonnie@users.noreply.github.com>
Signed-off-by: tterrysun <terry@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling of scope["root_path"] and scope["path"] differs from ASGI spec
3 participants