Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#18265 closed New feature (wontfix)

request.user cached value does not track request.session change

Reported by: Vlada Macek Owned by: nobody
Component: contrib.auth Version: master
Severity: Normal Keywords:
Cc: Melvyn Sopacua Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


During the Single-Sign On technique implementation I came to the need of replacing request.session with a new session or just setting request.session = None.

The descriptor in AuthenticationMiddleware nevertheless does not remember the session for which it sets the request._cached_user.

IMHO, the descriptor should cache the session key when it saves the _cached_user and allow _cached_user to be used only when the session key did not unchange.

Currently everyone who changes the session during the request processing HAS to dig into the AuthenticationMiddleware internals and modify the _cached_user to get valid request.user. That's hard to maintain.

I can offer the patch, but would like to get some response first.

Change History (5)

comment:1 Changed 7 years ago by Vlada Macek

Type: UncategorizedNew feature

comment:2 Changed 7 years ago by Melvyn Sopacua

Cc: Melvyn Sopacua added
Triage Stage: UnreviewedDesign decision needed

Submitter will provide patch if feature is considered useful.

comment:3 Changed 6 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

I'm sorry, but if replacing request.session isn't supported. It isn't possible to anticipate the side effects in general. It's up to you to deal with the specific consequences in your project.

comment:4 Changed 6 years ago by Vlada Macek

Thank you for the answer. I try to understand your position.

In my humble opinion every piece of code maintaining any cached value should be clever enough to track the cached value validity (or at least support such testing). It looks like it's currently the only thing standing in the way of supporting request.session replacing (which IMO is not too shameful technique by itself).

Last edited 6 years ago by Vlada Macek (previous) (diff)

comment:5 Changed 6 years ago by Aymeric Augustin

You can write to django-developers and see if other people would be interested by this change.

Note: See TracTickets for help on using tickets.
Back to Top