-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use new style middleware and catch exceptions to be sure to clear request in context #1188
Conversation
also, catch exceptions to be sure to clear request in context
ec41355
to
c9c02ae
Compare
Codecov Report
@@ Coverage Diff @@
## master #1188 +/- ##
==========================================
+ Coverage 97.30% 97.38% +0.08%
==========================================
Files 23 23
Lines 1260 1263 +3
Branches 204 204
==========================================
+ Hits 1226 1230 +4
Misses 16 16
+ Partials 18 17 -1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Added a changelog entry, and removed the "Using django-webtest with Middleware" section in `common_issues.rst`, as it's not an issue anymore now that `HistoricalRecords.context.request` is deleted in all cases (due to using a `finally` block).
@manelclos I added an exception variable to your code, in addition to adding a test and updating the documentation 🙂 |
This code was added in 341aec1 - when `HistoryRequestMiddleware` didn't delete the `HistoricalRecords.context.request` variable. The middleware class does now, so this can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thank you! 😊
Do review the changes I pushed, if you have any feedback :) Otherwise, I'll merge in a week's time.
Hi @ddabble all good! I didn't notice the error was documented already. Thanks for adding the tests and documentation. |
Now it also tests that the `request` attribute of `HistoricalRecords.context` actually exists while handling each request.
* Handle if `request` doesn't exist on the context in middleware The change in #1188 removed a check for if the request context had a "request" entry in it before trying to delete the request data. This has a side effect of breaking tests in order projects in very specific circumstances, where multiple requests pass through the middleware, concurrently, inside the same thread, as it means the middleware then may try to remove the request key on a context where it already has been removed. This shouldn't have any impact in real life scenarios. * Add changelog entry * Improvement of changelog for #1256 Also added a missing reference to the previously merged PR. --------- Co-authored-by: Anders <[email protected]>
Description
We caught a problem were the request was reused, causing a strange random behaviour:
Related Issue
Resolves #1189.
How Has This Been Tested?
Extensive pytest codebase using django-simple-history
Fixes the problem we were facing
Types of changes
Checklist:
pre-commit run
command to format and lint.AUTHORS.rst
CHANGES.rst