change in web-service api behavior: VALUE_OPTIONAL

change in web-service api behavior: VALUE_OPTIONAL

by Dorel Manolescu -
Number of replies: 1
Picture of Plugin developers

Hi

I noticed in the latest version of moodle (3.5.3+ (Build: 20181204) 3.6.1+ (Build: 20181220)) a change in terms of how the web-service API is working.

I am talking about parameter validation. In the past when calling a web-service (core or custom build) with a missing parameter an error was returned right away for the missing parameter without the need of custom validation. It seems that now we have to build our custom validations. I am not saying that is bad or good, I am just wondering if anyone has additional information on this.

For me it seems a little bit strange specially in terms of using the  "VALUE_OPTIONAL" all over the place for moodle core web-services. What is the purpose now for "VALUE_OPTIONAL" parameter if the validation is not done anyway? 

Let me know what you think.

Regards

Average of ratings: -
In reply to Dorel Manolescu

Re: change in web-service api behavior: VALUE_OPTIONAL

by Juan David Sanchez -

Hi,

We have noticed some errors, which I think could be related with this question.

When having the logs on "developper" level, and trying to add a new function to an existing service, there is an error message with a trace indicating something like this:

"External function parameters: Invalid OPTIONAL value specified"

When trying to remove the VALUE_OPTIONAL from the webservices, we do not get the afore mentioned error:

'summary' => new external_value(PARAM_RAW, 'Task summary', VALUE_OPTIONAL, ''),
Are there any API chages that we should be aware of?

---
UPDATE: 
Checking the documentation, I think that the cause of the error is clear for us: We had a top level optional parameter

"VALUE_OPTIONAL - if the value is not supplied => the value is ignored. Note that VALUE_OPTIONAL can't be used in top level parameters, it must be used only within array/objects key definition. If you need top level Optional parameters you should use VALUE_DEFAULT instead."


Best Regards,
Juan