Skip to content

The middleware does not always need to be last #221

@beruic

Description

@beruic

The installation instructions says that we shoul "Add maintenance_mode.middleware.MaintenanceModeMiddleware to settings.MIDDLEWARE as last middleware".

I think the documentation needs to be updated with guidance to when to divert from putting the middleware last.

In many cases, I think it is fine, but I would argue that there are cases where maintenance_mode.middleware.MaintenanceModeMiddleware should go before all other middleware.

Consider the following cases:

  • You need to run something to update all your users.
  • You deploy to the cloud, and you want to automate maintenance mode while migrating the database and replacing pods with the updated ones.

In both cases about, it is undesirable that other middleware, such as your seession middleware (if you use DB sessions), or the authentication middleware, hits the database.

I work on a project where both of the above (+ more) may apply, so we have put maintenance_mode.middleware.MaintenanceModeMiddleware top-most, and use MAINTENANCE_MODE_IGNORE_URLS to allow access to the admin and our URL for the k8s liveness probe.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions