Skip to content

Commit aa87e7c

Browse files
Tenzerddabble
andauthored
Handle missing request (#1256)
* 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]>
1 parent 2e8e9a5 commit aa87e7c

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Authors
6464
- Jake Howard (`RealOrangeOne <https://github.com/realorangeone>`_)
6565
- James Muranga (`jamesmura <https://github.com/jamesmura>`_)
6666
- James Pulec
67+
- Jeppe Fihl-Pearson (`Tenzer <https://github.com/Tenzer>`_)
6768
- Jesse Shapiro
6869
- Jihoon Baek (`jihoon796 <https://github.com/jihoon796>`_)
6970
- Jim Gomez

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Changes
44
Unreleased
55
----------
66

7-
- Allow ``HistoricalRecords.m2m_fields`` as str
7+
- Allow ``HistoricalRecords.m2m_fields`` as str (gh-1243)
8+
- Fixed ``HistoryRequestMiddleware`` deleting non-existent
9+
``HistoricalRecords.context.request`` in very specific circumstances (gh-1256)
810

911
3.4.0 (2023-08-18)
1012
------------------

simple_history/middleware.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def _context_manager(request):
1313
try:
1414
yield None
1515
finally:
16-
del HistoricalRecords.context.request
16+
try:
17+
del HistoricalRecords.context.request
18+
except AttributeError:
19+
pass
1720

1821

1922
@sync_and_async_middleware

0 commit comments

Comments
 (0)