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

Share session data across mounted routes #1351

Closed
wants to merge 8 commits into from

Conversation

florimondmanca
Copy link
Member

@florimondmanca florimondmanca commented Dec 5, 2021

Fixes #1261

The resolution here builds on @devsetgo's idea:

I would suggest checking if in Mount app=None as a way to determine whether to use ASGI path or "/".

Indeed, if we Mount(routes=...), the routes actually belong to the current app in the mount hierarchy, not to a fully separate app mounted on the sub-path, so session data on the current app should be shared with them.

Note that we otherwise keep the "use root_path for (fully) sub-mounted apps" for #233.

@florimondmanca florimondmanca added bug Something isn't working clean up Refinement to existing functionality labels Dec 5, 2021
@devsetgo
Copy link

devsetgo commented Dec 5, 2021

Fixes #1261

The resolution here builds on @devsetgo's idea:

I would suggest checking if in Mount app=None as a way to determine whether to use ASGI path or "/".

Indeed, if we Mount(routes=...), the routes actually belong to the current app in the mount hierarchy, not to a fully separate app mounted on the sub-path, so session data on the current app should be shared with them.

Note that we otherwise keep the "use root_path for (fully) sub-mounted apps" for #233.

This looks like a great solution... also, I now learned how to test the session cookie.

starlette/routing.py Outdated Show resolved Hide resolved
Co-authored-by: Marcelo Trylesinski <[email protected]>
Kludex
Kludex previously approved these changes Dec 6, 2021
Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

Answering your comment above: in terms of styling, either the current or using the attribute you previously had, it's fine by me.

I would've used session_path as there's no concept of "session_root_path" yet, so we can choose the name. But whatever you prefer is fine. :)

@Kludex Kludex dismissed their stale review December 6, 2021 20:41

Waiting for new changes.

@Kludex
Copy link
Member

Kludex commented Dec 6, 2021

Did you delete your comment? 🤔

@florimondmanca
Copy link
Member Author

@Kludex Yes 😅 I thought about an even more specific name, pushed it in a commit. Also I think we should use the attribute style, at least check on routes explicitly. I thought about what Mount(..., app=Router(...)) should do and I guess in that case we should definitely treat it as a separate thing, like we do for any app=....

Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

LGTM! :)

@Kludex
Copy link
Member

Kludex commented Dec 11, 2021

@florimondmanca Is there something else you'd want to check here?

@florimondmanca
Copy link
Member Author

florimondmanca commented Dec 11, 2021

I think this is an okay change — as in, it does solve the use case. But the "special case" flavor of it still makes me think I'd like @tomchristie's opinion. Tom? 😄

@0x1997
Copy link

0x1997 commented Jan 27, 2022

Any updates?

@tomchristie
Copy link
Member

Thanks @florimondmanca! Going to close this off in favour of #1512.

@tomchristie tomchristie deleted the fm/bug-sub-routes-sessions branch February 14, 2022 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working clean up Refinement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Starlette 0.15.0 breaks SessionMiddleware by adding ASGI Path for Subroutes using Mount
5 participants