Skip to content

Share session data across mounted routes#1351

Closed
florimondmanca wants to merge 8 commits intomasterfrom
fm/bug-sub-routes-sessions
Closed

Share session data across mounted routes#1351
florimondmanca wants to merge 8 commits intomasterfrom
fm/bug-sub-routes-sessions

Conversation

@florimondmanca
Copy link
Contributor

@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
@florimondmanca florimondmanca requested a review from Kludex December 5, 2021 13:37
@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.

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Kludex
Kludex previously approved these changes Dec 6, 2021
Copy link
Owner

@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
Owner

Kludex commented Dec 6, 2021

Did you delete your comment? 🤔

@florimondmanca
Copy link
Contributor 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
Owner

@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
Owner

Kludex commented Dec 11, 2021

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

@florimondmanca
Copy link
Contributor 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?

@lovelydinosaur
Copy link

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

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