mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Fix #5016 - Views mutate user object when using force_request
This commit is contained in:
parent
06d64bd74a
commit
958fb8e734
|
@ -4,6 +4,7 @@
|
||||||
# to make it harder for the user to import the wrong thing without realizing.
|
# to make it harder for the user to import the wrong thing without realizing.
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import copy
|
||||||
import io
|
import io
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -22,7 +23,7 @@ from rest_framework.settings import api_settings
|
||||||
|
|
||||||
|
|
||||||
def force_authenticate(request, user=None, token=None):
|
def force_authenticate(request, user=None, token=None):
|
||||||
request._force_auth_user = user
|
request._force_auth_user = copy.deepcopy(user)
|
||||||
request._force_auth_token = token
|
request._force_auth_token = token
|
||||||
|
|
||||||
|
|
||||||
|
@ -268,7 +269,7 @@ class APIClient(APIRequestFactory, DjangoClient):
|
||||||
Forcibly authenticates outgoing requests with the given
|
Forcibly authenticates outgoing requests with the given
|
||||||
user and/or token.
|
user and/or token.
|
||||||
"""
|
"""
|
||||||
self.handler._force_user = user
|
self.handler._force_user = copy.deepcopy(user)
|
||||||
self.handler._force_token = token
|
self.handler._force_token = token
|
||||||
if user is None:
|
if user is None:
|
||||||
self.logout() # Also clear any possible session info if required
|
self.logout() # Also clear any possible session info if required
|
||||||
|
|
Loading…
Reference in New Issue
Block a user