Please Note this is a very Django specific question, so if you know the Django Rest Framework you will understand it
So I have a view in Django rest framework with an update function over ridden and a _has_permission helper function
def update(self, request, *args, **kwargs):
permission, message = self._has_permission(data=request.data)
if not permission:
return Response({'error': message}, status=status.HTTP_403_FORBIDDEN)
return super().update(request, *args, **kwargs)
def _has_permission(self, data):
"""
Resolves if the logged in user has permission to update the data given the type of data
:param data:
:return:
"""
data['user_type'] = data['user_type'] if ('user_type' in data and data['user_type']) else None
....
some checks
....
return True, 'Has Permission'
In the case where the function _has_permission() sees that 'user_type' is not in data, it sets data['user_type'] = None in the function, but when it comes out request.data['user_type'] now exists and becomes None as well
How is this dictionary being shared across two different scopes. I thought functions have their own scopes