Update djblets to support MIDDLEWARE setting.

Review Request #11910 — Created Jan. 7, 2022 and submitted — Latest diff uploaded

Information

Djblets
release-2.x

Reviewers

In 1.10, Django changed the way middleware works. Several of the
built-in methods were coalesced together into a callable that processes
the request, delegates to other middleware, and then processes the
response. In order to distinguish between the invocation methods, they
renamed the setting from MIDDLEWARE_CLASSES to MIDDLEWARE.

For most of our middleware classes, we can just inherit from the new
MiddlewareMixin class. This allows middleware classes to work
correctly no matter which version of Django they're using.

The big wrinkle here was in extension middleware. To start with, I'm
pretty sure that nobody is using it (our documentation claims that the
middleware attribute should be a list of module paths to the
middleware classes to match the setting, but the implementation was
expecting a list of classes themselves). More importantly, the way that
they were processed (instantiating the classes at init time and then
calling the old process_* methods) wouldn't work with new-style
middleware.

I've added some detection to figure out whether each entry in the list
is old- or new-style, and then depending on what the setting is, do the
right thing. We can run old-style middleware with the new setting, but
can't run new-style middleware with the old setting. Appropriate
warnings have been added in these situations. This includes new test
cases to check that the various different combinations run the
middleware as expected.

  • Ran unit tests.
  • Used djblets middleware (logging, settings) with Review Board.

Diff Revision 3

This is not the most recent revision of the diff. The latest diff is revision 5. See what's changed.

orig
1
2
3
4
5

Commits

First Last Summary ID Author
Update djblets to support MIDDLEWARE setting.
In 1.10, Django changed the way middleware works. Several of the built-in methods were coalesced together into a callable that processes the request, delegates to other middleware, and then processes the response. In order to distinguish between the invocation methods, they renamed the setting from `MIDDLEWARE_CLASSES` to `MIDDLEWARE`. For most of our middleware classes, we can just inherit from the new `MiddlewareMixin` class. This allows middleware classes to work correctly no matter which version of Django they're using. The big wrinkle here was in extension middleware. To start with, I'm pretty sure that nobody is using it (our documentation claims that the `middleware` attribute should be a list of module paths to the middleware classes to match the setting, but the implementation was expecting a list of classes themselves). More importantly, the way that they were processed (instantiating the classes at init time and then calling the old `process_*` methods) wouldn't work with new-style middleware. I've added some detection to figure out whether each entry in the list is old- or new-style, and then depending on what the setting is, do the right thing. We can run old-style middleware with the new setting, but can't run new-style middleware with the old setting. Appropriate warnings have been added in these situations. This includes new test cases to check that the various different combinations run the middleware as expected. Testing Done: - Ran unit tests. - Used djblets middleware (logging, settings) with Review Board.
0dbcf3d33c62a70154cbf96def6c70e696395d1f David Trowbridge
djblets/extensions/extension.py
djblets/extensions/manager.py
djblets/extensions/middleware.py
djblets/extensions/tests/test_middleware.py
djblets/http/middleware.py
djblets/integrations/manager.py
djblets/integrations/middleware.py
djblets/integrations/tests/test_manager.py
djblets/log/middleware.py
djblets/siteconfig/middleware.py
djblets/testing/urls.py
Loading...