File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,20 @@ be the *last* middleware on the *last* layer (i.e. the route handler).
130130 ]
131131 )
132132
133+ Constraints and plugins
134+ ~~~~~~~~~~~~~~~~~~~~~~~
135+
136+ When using plugins that add middleware(s), it is important to understand that these
137+ middleware(s) are added *after * middlewares defined on the application and *before * middlewares defined on the other layers.
138+
139+ Constraints are evaluated after all middlewares have been added though, so an order constraint on a middleware added by
140+ a plugin has to take into account the position it is being added to.
141+
142+ Most of the time in a plugin you would do ``app_config.middleware.append(MyCustomMiddleware) `` which will be
143+ ok if it has no constraints attached.
144+
145+ Now suppose that ``MyCustomMiddleware `` has the constraint ``first=True `` then the correct way to add it is to do
146+ ``app_config.middleware.insert(0, MyCustomMiddleware()) `` so that it is the first middleware in the stack.
133147
134148
135149Migrating from ``MiddlewareProtocol `` / ``AbstractMiddleware ``
You can’t perform that action at this time.
0 commit comments