-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Describe the bug
If you try to call a webservice function that takes an external_single_structure not wrapped in an external_multiple_structure, to_dict() does not properly handle the passed value. This results in Error Code: Invalid parameter value detected when calling an affected service.
To Reproduce
Steps to reproduce the behavior:
-
Create a user that can access
local_modcontentservice_update_page_content(which has such a parameter) -
call e.g.
moodle('core_calendar_get_calendar_events') moodle.core.calendar.get_calendar_events()
these succeed
-
call e.g.
moodle('core_calendar_get_calendar_events', options={'userevents': 1})
which fails with
Error Code: Invalid parameter value detected (options => Invalid parameter value detected (Only arrays accepted. The bad value is: 'userevents')
(the key of the dict is used as the value. A look in Wireshark shows that the value (1) is not part of the HTTP request. Putting multiple keys in the dictionary will send multiple
optionsform items, each with one of the dict keys as the value) -
call e.g.
moodle.core.calendar.get_calendar_events(options=Events.Options(userevents=1))
which fails with
Error Code: Invalid parameter value detected (options => Invalid parameter value detected (Only arrays accepted. The bad value is: 'Events.Options(userevents=1, siteevents=1, timestart=0, timeend=0, ignorehidden=1)')
Expected behavior
Passing the parameters should be translated into the form expected by Moodle, and the webservice function should succeed
Desktop (please complete the following information):
- Python Version: 3.12
- Version: 0.24.1
Additional context
The problem is pretty clearly in https://github.com/hexatester/moodlepy/blob/master/moodle/utils/helper.py. Top-level single structures are probably not the only case where the method will misbehave; single structures inside single structures seem like they would also fail.
I wouldn't mind working on a fix, but I'm pretty new to Moodle. I would of course test the function properly, but you'd need to make sure that I don't screw up with defining the test cases.