Skip to content

Commit 908a4fa

Browse files
author
Ross Mechanic
authored
Added documentation for failures resulting from django-webtest (#392)
1 parent 4c60246 commit 908a4fa

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/reference.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Common Issues
22
=============
33

4+
Tracking Custom Users
5+
---------------------
6+
47
- ``fields.E300``::
58

69
ERRORS:
@@ -13,3 +16,26 @@ Common Issues
1316
The reason for this, is that unfortunately ``HistoricalRecords``
1417
cannot be set directly on a swapped user model because of the user
1518
foreign key to track the user making changes.
19+
20+
Using django-webtest with Middleware
21+
------------------------------------
22+
23+
When using django-webtest_ to test your Django project with the
24+
django-simple-history middleware, you may run into an error similar to the
25+
following::
26+
27+
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`))')
28+
29+
.. _django-webtest: https://github.com/django-webtest/django-webtest
30+
31+
This error occurs because ``django-webtest`` sets
32+
``DEBUG_PROPOGATE_EXCEPTIONS`` to true preventing the middleware from cleaning
33+
up the request. To solve this issue, add the following code to any
34+
``clean_environment`` or ``tearDown`` method that
35+
you use:
36+
37+
.. code-block::python
38+
39+
from simple_history.middleware import HistoricalRecords
40+
if hasattr(HistoricalRecords.thread, 'request'):
41+
del HistoricalRecords.thread.request

0 commit comments

Comments
 (0)