Skip to content
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

history_user error during usage of simple_history.middleware.HistoryRequestMiddleware #114

Closed
isn85 opened this issue Sep 9, 2014 · 2 comments · Fixed by #115
Closed

Comments

@isn85
Copy link

isn85 commented Sep 9, 2014

Hello!
I've written some automatic tests with WebTest. During execution of testsuite test data is generated automatically (some objects are created dynamically). If I don't use simple_history.middleware.HistoryRequestMiddleware, than all tests run successfully. If I use it, than the following error occurs:
ValueError(u'Cannot assign "<django.utils.functional.SimpleLazyObject object at 0x982332c>": "HistoricalActor.history_user" must be a "User" instance.

Could you, please, tell me the direction on digging for solving such problem.

@macro1
Copy link
Collaborator

macro1 commented Sep 9, 2014

Is the full error something like this:

ValueError: Cannot assign "<SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x7f08ddb4e470>>": "HistoricalCustomUser.history_user" must be a "CustomUser" instance.

It looks like we are not handling anonymous users. Try signing in for that test and trying again. If you would like to submit a PR, the test could be written in the test_admin.py module with the other middleware test.

The fix is pretty simple... We just need to make a check for is_authenticated() when we're assigning the value in HistoricalRecords.get_history_user().

@macro1
Copy link
Collaborator

macro1 commented Sep 9, 2014

Apparently someone beat me to the punch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants