Skip to content

[BUG 🐞] to_dict() does not handle top-level single structures correctly. #23

@SillyFreak

Description

@SillyFreak

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:

  1. Create a user that can access local_modcontentservice_update_page_content (which has such a parameter)

  2. call e.g.

    moodle('core_calendar_get_calendar_events')
    moodle.core.calendar.get_calendar_events()

    these succeed

  3. 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 options form items, each with one of the dict keys as the value)

  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions