openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

ODataModelV2: Calling a function that returns an array of Strings results in an error

Open chott92 opened this issue 1 month ago • 5 comments

What is the issue and how can we reproduce it?

When Using a sap.ui.model.odata.v2.ODataModel to call an OData Function on an OData V2 Service that returns an Array of Strings, the result will not be parsed correctly in the OData Model and result in a JavaScript Error on Client Side:

Uncaught TypeError: Cannot assign to read only property '0' of string 'Foo'
    at String.<anonymous> (ODataModel.js:1625:20)
    at fnEach (each.js?eval:67:21)
    at constructor._importData (ODataModel.js:1591:4)
    at String.<anonymous> (ODataModel.js:1540:17)
    at fnEach (each.js?eval:61:21)
    at constructor._importData (ODataModel.js:1538:4)
    at constructor._processSuccess (ODataModel.js:4544:11)
    at processResponse (ODataModel.js:3861:11)
    at handleSuccess (ODataModel.js:3915:7)
    at handleSuccess (ODataModel.js:3596:5)

(For reference to navigate the sourcecode: In this example, UI5 version 1.141.2 is used)

A Reproducing example (with instructions for setup) can be found here: https://github.com/chott92/openui5-sample

From what I did analyze on my own, it appears that with String Arrays, the Model takes one recursive step too far into the result parsing, resulting in calling a each() on the Strings themselves, which results in the error shown on the JavaScript Console.

Which OpenUI5 version is your project targeting?

1.96, 1.136 (reproduced on both)

Is the issue device- or browser-specific?

The Issue Seems not to be browser specific, since it appears to be located directly in the JavaScript Code of the ODataModel.

Confirmation

  • [x] I have searched the existing issues and reviewed the relevant documentation as well as the API reference.
  • [x] I am not disclosing any internal or sensitive information.

chott92 avatar Nov 18 '25 10:11 chott92

The repo https://github.com/chott92/openui5-sample seems to start an OData V4 service while the app refers to a v2.ODataModel. Am I missing something? The spec version should align with the version of the ODataModel class. Ensure that the OData service is correct in accordance with the OData specification. Not sure if OData V2 actually allows FunctionImport returning a collection of primitive string values.

boghyon avatar Nov 20 '25 12:11 boghyon

The repo https://github.com/chott92/openui5-sample seems to start an OData V4 service while the app refers to a **v2.**ODataModel. Am I missing something? The spec version should align with the version of the ODataModel class. Ensure that the OData service is correct in accordance with the OData specification. Not sure if OData V2 actually allows FunctionImport returning a collection of primitive string values.

The Service in the repo uses a CAP Service, which normally delivers OData V4, correct. But there is an add-on to CAP so that it also can deliver an OData V2 service, which is active and used in my example. So it is actually using an OData V2 endpoint in the example, otherwise the OData V2 model would not be able to parse the OData Metadata at all. The Error occurs after fetching the Metadata, calling the OData Function in the parsing of the function return.

As for the OData V2 Specification, it does state that Service Operations (which functions are) can return a collection of primitive values, as stated in the last point (16) on this page: https://www.odata.org/documentation/odata-version-2-0/json-format/

chott92 avatar Nov 25 '25 11:11 chott92

Thanks, I was able to reproduce the issue. While the data service is OData V2, its response doesn't seem to follow the OData V2 documentation which states:

If a Service Operation returns a collection of primitive values, then the primitives are returned as a JSON array as shown in the example below.

{ "d" : [ 0, 1, 2 ] }

The service from the sample repo currently responds with {"d":{"results":["Foo","Bar","Baz","FooBar"]}} in the $batch. Without the "results" as shown in the OData V2 doc, I could see the success handler of the v2.ODataModel#callFunction being triggered.

boghyon avatar Nov 25 '25 15:11 boghyon

https://github.com/oasis-tcs/odata-specs/issues/2145 should be clarified first. The above linked OData V2 documentation might not be correct.

In the meantime, could you share if there's a particular reason for choosing OData V2 while using CAP? Is there something missing in the OData V4 stack that is needed in your project and supported in V2?

boghyon avatar Nov 26 '25 08:11 boghyon

I Was Using OData V2 with CAP mostly for development and testing purposes.

The project I'm currently working on is a platform that, as one of their features, has a generalized OData Client that the customer can use to call their OData Systems (and of course, the platform uses OpenUI5 as Frontend). The requirements were support for both V2 and V4. During the development I was working with the CAP system to ensure that all functionality is working properly for both versions, which in the given case here, it did not.

So we're not specifically using CAP as an OData V2 endpoint, we just didn't have that many different options for a development environment.

chott92 avatar Nov 26 '25 15:11 chott92