Skip to content

Commit

Permalink
Updated docs for #1188
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ddabble committed Aug 3, 2023
1 parent a7a30a6 commit 2e0d0e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Unreleased
- Dropped support for Django 4.0, which reached end-of-life on 2023-04-01 (gh-1202)
- Added support for Django 4.2 (gh-1202)
- Made ``bulk_update_with_history()`` return the number of model rows updated (gh-1206)
- Fixed ``HistoryRequestMiddleware`` not cleaning up after itself (i.e. deleting
``HistoricalRecords.context.request``) under some circumstances (gh-1188)

3.3.0 (2023-03-08)
------------------
Expand Down
23 changes: 0 additions & 23 deletions docs/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,6 @@ Tracking Custom Users
cannot be set directly on a swapped user model because of the user
foreign key to track the user making changes.

Using django-webtest with Middleware
------------------------------------

When using django-webtest_ to test your Django project with the
django-simple-history middleware, you may run into an error similar to the
following::

django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`test_env`.`core_historicaladdress`, CONSTRAINT `core_historicaladdress_history_user_id_0f2bed02_fk_user_user_id` FOREIGN KEY (`history_user_id`) REFERENCES `user_user` (`id`))')

.. _django-webtest: https://github.com/django-webtest/django-webtest

This error occurs because ``django-webtest`` sets
``DEBUG_PROPAGATE_EXCEPTIONS`` to true preventing the middleware from cleaning
up the request. To solve this issue, add the following code to any
``clean_environment`` or ``tearDown`` method that
you use:

.. code-block:: python
from simple_history.middleware import HistoricalRecords
if hasattr(HistoricalRecords.context, 'request'):
del HistoricalRecords.context.request
Using F() expressions
---------------------
``F()`` expressions, as described here_, do not work on models that have
Expand Down

0 comments on commit 2e0d0e1

Please sign in to comment.