openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

Request: Hide __metadata field in OData Payload

Open mitch-b opened this issue 9 years ago • 5 comments

I have a request to optionally send the __metadata Object property along with a payload as part of ODataModel.prototype._processChange (when requested, for example, by v2_oDataModel.submitChanges()).

If I am using a back-end system (for example, ASP.NET Web API OData v1-3) that tries to bind an incoming request to a known typed model, and that known model doesn't contain __metadata, the binding fails and an Internal Service Error (HTTP 500) is returned to the client - which surprisingly isn't a Bad Request.

This could be avoided if that property is omitted from the POST sent to the server. It seems that oData.__metadata is used in a couple of ways, but doesn't seem to be critical path for the response being ultimately sent in _processChange.

Before v1.30.10, knowing that it wasn't a good solution, we could modify the non-public object's properties to say,

delete oModel.oData[sPath].__metadata;

This is fine until you decide you'd like to upgrade the UI5 runtime, and you're stuck.

Maybe there's another avenue to go down, but hiding this Object in the payload seems suitable to me (who may not know what broader impacts this has). Thanks.

mitch-b avatar Feb 23 '17 17:02 mitch-b

Hi @mitch-b,

Thanks for the ticket. Internal incident 1770050601 has been opened for this issue.

PetyoKostakov avatar Mar 06 '17 13:03 PetyoKostakov

Hi,

the __metadata property is not optional in the json representation of an OData Entry:

http://www.odata.org/documentation/odata-version-2-0/json-format/

See '7. Representing Entries'.

At least the uri must be passed. You also need the metadata for eTag handling.

BR, Jan

loginger avatar Mar 09 '17 09:03 loginger

@loginger The spec says "An optional "__metadata" name/value pair is the only pair that should be included on the object that does not directly represent a Property of the Entry being represented." The "optional" column of the table talks about individual properties, I would say. Thus I think if you have "__metadata" then you also have "uri". But I do not agree that "__metadata" is not optional.

ThomasChadzelek avatar Mar 09 '17 11:03 ThomasChadzelek

even if the __metadata is optional the service should be able to handle both cases.

loginger avatar Mar 09 '17 13:03 loginger

Is it ambiguous enough that implementers of the OData protocol may approach it differently? Is it ensured that the __metadata property exists on the the request (more than just the response)?

I can totally understand receiving __metadata in each object in the response from the OData server (to get required uri), but posting updates back to the server is noise when you're already MERGE/POST/PUT/DELETE-ing to a specific url.

I understand the need for it if you're using eTag, in which case, your back-end service is probably going to support this __metadata object.

If we decide that it's not proper to remove the __metadata object (for backends which do not support it), then I'm left with no choice but to create my own workaround (as well as anybody else who uses a back-end which doesn't support it). In which case, I've been relegated to creating separate .update(mPayload, ...) calls to manually craft what data gets sent to the server. Seems like code smell when the v2.ODataModel.submitChanges() could perform a similar end-result.

mitch-b avatar Mar 09 '17 19:03 mitch-b