Skip to content

Commit 958fb8e

Browse files
committed
Fix #5016 - Views mutate user object when using force_request
1 parent 06d64bd commit 958fb8e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

rest_framework/test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# to make it harder for the user to import the wrong thing without realizing.
55
from __future__ import unicode_literals
66

7+
import copy
78
import io
89

910
from django.conf import settings
@@ -22,7 +23,7 @@
2223

2324

2425
def force_authenticate(request, user=None, token=None):
25-
request._force_auth_user = user
26+
request._force_auth_user = copy.deepcopy(user)
2627
request._force_auth_token = token
2728

2829

@@ -268,7 +269,7 @@ def force_authenticate(self, user=None, token=None):
268269
Forcibly authenticates outgoing requests with the given
269270
user and/or token.
270271
"""
271-
self.handler._force_user = user
272+
self.handler._force_user = copy.deepcopy(user)
272273
self.handler._force_token = token
273274
if user is None:
274275
self.logout() # Also clear any possible session info if required

0 commit comments

Comments
 (0)