zsoldosp / django-currentuser

Conveniently store reference to request user on thread/db level.
BSD 3-Clause "New" or "Revised" License
139 stars 40 forks source link

Avoid closure around request scope #2

Open belugame opened 7 years ago

belugame commented 7 years ago

Currently the order in which this middleware is inserted in respect to AuthenticationMiddleware and SessionMiddleware does not matter as we use a closure that returns the request-scope only on-demand.

This closure can fail in certain setups (see https://github.com/PaesslerAG/django-currentuser/pull/1#discussion_r112193050) and seems avoidable. Right now nothing speaks against requiring a fixed order where ThreadLocalUserMiddleware is only allowed after the other two.

See: https://github.com/PaesslerAG/django-currentuser/blob/mb-prepare-package/django_currentuser/middleware.py#L29