-
Notifications
You must be signed in to change notification settings - Fork 158
Open
Description
Hi, two methods of the FrappeClient class use {} as a default value for its parameters params. This practice may cause some unexpected behaviors in some contexts. This problem arises because of the way python variables (names) work. When modifying these parameters (e.g appending items to it) the method still uses the same default value:
def append_item(item, data=[]):
data.append(item)
return data>> append_item(1)
[1]
>> append_item(2) # [2] is the expected value
[1, 2]So that, the workaround is always using the None type as the default of the parameters
These methods are:
get_apipost_api
Solution:
def get_api(self, method, params=None):
if params is None:
params = {}
else:
params = dict(params)
res = self.session.get(self.url + '/api/method/' + method + '/', params=params)
return self.post_process(res)
def post_api(self, method, params=None):
if params is None:
params = {}
else:
params = dict(params)
res = self.session.post(self.url + '/api/method/' + method + '/', params=params)
return self.post_process(res)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels