cancel
Showing results for 
Search instead for 
Did you mean: 

v2 oData DELETE request key values are not URL encoded

beanonradar
Explorer

Can anybody confirm this? Is it a bug? Both requests taken from request payload from the batch request, please notice that KEY01 contains a value with a white space (leer zeich):

When I edit a dataset via setProperty and submitChanges everything is fine:

MERGE MY_DATASet(TABNAME='MYTABLE',CV='',ID=0,KEY01='leer%20zeich',KEY02='xxx',KEY03='yyy',KEY04='zzz',KEY05='',KEY06='',KEY07='',KEY08='',KEY09='',KEY10='') HTTP/1.1

This requests completes successfully, I assume because of the correct url-encoding of the value in KEY01.

Delete request fails with the error message: "The Data Services Request could not be understood due to malformed syntax". I assume this fails because the value in KEY01 is NOT url-encoded.

DELETE MY_DATASet(TABNAME='MYTABLE',CV='',ID=0,KEY01='leer zeich',KEY02='xxx',KEY03='yyy',KEY04='zzz',KEY05='',KEY06='',KEY07='',KEY08='',KEY09='',KEY10='') HTTP/1.1

Is there a workaround for this problem?

Accepted Solutions (1)

Accepted Solutions (1)

boghyon
Product and Topic Expert
Product and Topic Expert

Whenever creating a path to access an entity (e.g. when doing CRUD), make sure to use the API createKey from the ODataModel. For example:

const myODataModel = this.getOwnerComponent().getModel(/*modelName*/);
const createPath = () => myODataModel.createKey("/MY_DATASet", {
  KEY01: "leer zeich", // gets encoded as 'leer%20zeich'
  KEY02: "xxx",
  // ...
});
myODataModel.metadataLoaded().then(() => myODataModel.remove(createPath()));

The API ensures encoding URI parts (via encodeURIComponent internally) accordingly with other benefits mentioned in https://stackoverflow.com/a/47016070.

Answers (3)

Answers (3)

former_member227918
Active Contributor

javascript function encodeURIComponent(string uri) would be the one workaround.

JavaScript encodeURIComponent

smarchesini
Active Contributor

Hi Timo,


I see in the DELETE call the key01 miss in the value the escape character %20.
Some times is necessary refresh the metadata cache and the application cache for resolve this issue.
Maybe solve the problem

Sebastiano

beanonradar
Explorer
0 Kudos

Hi Sebastiano, I deleted the metadata cache with the transaction /IWBEP/CACHE_CLEANUP. This had no effect on this issue. How can I delete the application cache? I could not find anything useful about this by googling.

smarchesini
Active Contributor
0 Kudos

Launch this 4 report from se38
/UI2/PAGE_CACHE_RESET
/UI2/INVALIDATE_CLIENT_CACHES

/UI5/APP_INDEX_CALCULATE

/UI2/INVALIDATE_GLOBAL_CACHES

Rebuild the segw with button:



And did you build the call with createkey on SAPUI5 code ?
Like :

var oModel = this.getView().getModel("nameModel");

var sPath = oModel.createKey("/MY_DATASet", {
						"TABNAME": param1,
						"CV": param2,
						****etc*******
					});

oModel.remove(sPath , {
                success: function () {
			*****
		},
		error: function (msg) {
			*****
		}
	});
}.bind(this)));

karthikarjun
Active Contributor
0 Kudos

Hi Timo, I can see two spots to handle this problem.

No1:

Put breakpoint in Gateway delete entity set and execute the delete operation from UI. If request hits the breakpoint, then keep your eye on gateway delete entity set class.

No2:

If you request did not reach gateway, at this scenario, avoid white space and check the key properties are maintained as per the gateway property.

Regards,

Karthik Arjun

beanonradar
Explorer
0 Kudos

Hi Karthik,

it's definitely scenario No2. The request does not reach the gateway. When I avoid key values with spaces the request passes just fine. So the only solution is to avoid whitespaces in key values when using delete requests?

karthikarjun
Active Contributor
0 Kudos

Hi Timo, Yes can you remove white space from request?