Refresh of OData model metadata returns invalid values
OpenUI5 version: latest ( 1.38.5 (2016-07-27) )
Browser/version (+device/version): Chrome 51.0.2704.106 m (64-bit) Firefox 47.0
URL (minimal example if possible): Not available because OData API is used
Steps to reproduce the problem:
- Create an ODataModel and show some information with ui5
- Change the according metadata of the oData API and refresh the metadata model
- The refreshed odata model does not represent the updated oData API
What is the expected result? As you can see in the XML below. The Metadata contains entityTypes and entityContainers. With an update of the metadata the types and containers should be updated in the ui5 odata model too.
What happens instead? The entityTypes are updated correctly. The entityContainer is updated as well but somehow the references of some properties of the entityContainer are corrupted and point to wrong entityTypes.
Any other information? (attach screenshot if possible)
The following piece of UI5 code demonstrates the problem:
oDataModel.refreshMetadata().then( function( response ) {
console.log( that._oDataModel.getServiceMetadata() );
debugger;
} );
When the metadata is refreshed the promise returns and the attached function is called. As argument this function gets the xml data from the server. This response is valid and correct. See the xml above how this xml can look like. There you can see that the entityContainer contains properties with an according entityType.
<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="com.sap.iotservices.mms">
<EntityType Name="entity0">
<Key>
<PropertyRef Name="G_CREATED" />
<PropertyRef Name="C_DEVICE_TYPE" />
<PropertyRef Name="C_MESSAGE_TYPE" />
<PropertyRef Name="C_PROCESSING_SERVICE" />
<PropertyRef Name="C_PROPERTIES" />
</Key>
<Property xmlns:mms="com.sap.iotservices.mms" Name="G_CREATED" Type="Edm.DateTime" mms:ColumnName="G_CREATED" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="C_DEVICE_TYPE" Type="Edm.String" mms:ColumnName="C_DEVICE_TYPE" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="C_MESSAGE_TYPE" Type="Edm.String" mms:ColumnName="C_MESSAGE_TYPE" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="C_PROCESSING_SERVICE" Type="Edm.String" mms:ColumnName="C_PROCESSING_SERVICE" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="C_PROPERTIES" Type="Edm.String" mms:ColumnName="C_PROPERTIES" />
</EntityType>
<EntityType Name="entity1">
<Key>
<PropertyRef Name="G_CREATED" />
<PropertyRef Name="C_KEY" />
<PropertyRef Name="C_VALUE" />
</Key>
<Property xmlns:mms="com.sap.iotservices.mms" Name="G_CREATED" Type="Edm.DateTime" mms:ColumnName="G_CREATED" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="C_KEY" Type="Edm.String" mms:ColumnName="C_KEY" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="C_VALUE" Type="Edm.String" mms:ColumnName="C_VALUE" />
</EntityType>
<EntityType Name="entity2">
<Key>
<PropertyRef Name="G_CREATED" />
<PropertyRef Name="G_METRIC" />
<PropertyRef Name="G_VALUE" />
<PropertyRef Name="G_COMPONENT" />
<PropertyRef Name="G_PROCESS" />
</Key>
<Property xmlns:mms="com.sap.iotservices.mms" Name="G_CREATED" Type="Edm.DateTime" mms:ColumnName="G_CREATED" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="G_METRIC" Type="Edm.String" mms:ColumnName="G_METRIC" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="G_VALUE" Type="Edm.Double" mms:ColumnName="G_VALUE" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="G_COMPONENT" Type="Edm.String" mms:ColumnName="G_COMPONENT" />
<Property xmlns:mms="com.sap.iotservices.mms" Name="G_PROCESS" Type="Edm.String" mms:ColumnName="G_PROCESS" />
</EntityType>
<EntityType Name="entitySet">
<Key>
<PropertyRef Name="name" />
</Key>
<Property Name="schema" Type="Edm.String" />
<Property Name="name" Type="Edm.String" m:FC_TargetPath="SyndicationTitle" />
<Property Name="count" Type="Edm.String" />
</EntityType>
<EntityContainer xmlns:mms="com.sap.iotservices.mms" Name="DEMO" m:IsDefaultEntityContainer="true" mms:SchemaName="DEMO">
<EntitySet Name="count" EntityType="com.sap.iotservices.mms.entitySet" />
<EntitySet Name="T_IOT_PROCESSING_SERVICE_CONFIG" EntityType="com.sap.iotservices.mms.entity0" mms:TableName="T_IOT_PROCESSING_SERVICE_CONFIG" />
<EntitySet Name="T_IOT_CONFIG" EntityType="com.sap.iotservices.mms.entity1" mms:TableName="T_IOT_CONFIG" />
<EntitySet Name="T_IOT_MONITOR_LOG" EntityType="com.sap.iotservices.mms.entity2" mms:TableName="T_IOT_MONITOR_LOG" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Now the console log statement is executed which should print the serviceMetadata. It is expected that this metadata is equals the metadata shown in the xml above. Unfortunately thats not the case. See the json below which is the Metadata object serialized as json. I know that is a bigger object but it perfectly shows the issue. When you compare the entityType array than this array matches the entityTypes from the xml. Each entityType ID is listed. Now have a look at the entityContainer. The entityContainer contains all the names which are listed in the XML but each name references an entityType. During comparison it show up that these types are mixed and do NOT represent the XML state.
Example: In the XML the tableName T_IOT_PROCESSING_SERVICE_CONFIG refers to com.sap.iotservices.mms.entity1 in the javasript it refers to com.sap.iotservices.mms.entity0 and even more worse is that another tableName T_IOT_CONFIG now points to com.sap.iotservices.mms.entity0 aswell.
Forcing refreshes on the model does not solved the issue.
Hope the issue is clear enough, sorry for the long examples but they make the issue very clear.
{
"version": "1.0",
"dataServices": {
"dataServiceVersion": "1.0",
"schema": [
{
"namespace": "com.sap.iotservices.mms",
"entityType": [
{
"name": "entity0",
"key": {
"propertyRef": [
{
"name": "G_CREATED"
},
{
"name": "C_KEY"
},
{
"name": "C_VALUE"
}
]
},
"property": [
{
"name": "G_CREATED",
"type": "Edm.DateTime",
"extensions": [
{
"name": "ColumnName",
"value": "G_CREATED",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "C_KEY",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "C_KEY",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "C_VALUE",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "C_VALUE",
"namespace": "com.sap.iotservices.mms"
}
]
}
]
},
{
"name": "entity1",
"key": {
"propertyRef": [
{
"name": "G_CREATED"
},
{
"name": "G_METRIC"
},
{
"name": "G_VALUE"
},
{
"name": "G_COMPONENT"
},
{
"name": "G_PROCESS"
}
]
},
"property": [
{
"name": "G_CREATED",
"type": "Edm.DateTime",
"extensions": [
{
"name": "ColumnName",
"value": "G_CREATED",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_METRIC",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "G_METRIC",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_VALUE",
"type": "Edm.Double",
"extensions": [
{
"name": "ColumnName",
"value": "G_VALUE",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_COMPONENT",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "G_COMPONENT",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_PROCESS",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "G_PROCESS",
"namespace": "com.sap.iotservices.mms"
}
]
}
]
},
{
"name": "entitySet",
"key": {
"propertyRef": [
{
"name": "name"
}
]
},
"property": [
{
"name": "schema",
"type": "Edm.String"
},
{
"name": "name",
"type": "Edm.String",
"FC_TargetPath": "SyndicationTitle"
},
{
"name": "count",
"type": "Edm.String"
}
]
},
{
"name": "entity2",
"key": {
"propertyRef": [
{
"name": "G_CREATED"
},
{
"name": "G_METRIC"
},
{
"name": "G_VALUE"
},
{
"name": "G_COMPONENT"
},
{
"name": "G_PROCESS"
}
]
},
"property": [
{
"name": "G_CREATED",
"type": "Edm.DateTime",
"extensions": [
{
"name": "ColumnName",
"value": "G_CREATED",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_METRIC",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "G_METRIC",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_VALUE",
"type": "Edm.Double",
"extensions": [
{
"name": "ColumnName",
"value": "G_VALUE",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_COMPONENT",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "G_COMPONENT",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "G_PROCESS",
"type": "Edm.String",
"extensions": [
{
"name": "ColumnName",
"value": "G_PROCESS",
"namespace": "com.sap.iotservices.mms"
}
]
}
]
}
],
"entityContainer": [
{
"name": "DEMO",
"isDefaultEntityContainer": "true",
"entitySet": [
{
"name": "count",
"entityType": "com.sap.iotservices.mms.entitySet"
},
{
"name": "T_IOT_CONFIG",
"entityType": "com.sap.iotservices.mms.entity0",
"extensions": [
{
"name": "TableName",
"value": "T_IOT_CONFIG",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "T_IOT_MONITOR_LOG",
"entityType": "com.sap.iotservices.mms.entity1",
"extensions": [
{
"name": "TableName",
"value": "T_IOT_MONITOR_LOG",
"namespace": "com.sap.iotservices.mms"
}
]
},
{
"name": "T_IOT_PROCESSING_SERVICE_CONFIG",
"entityType": "com.sap.iotservices.mms.entity0",
"extensions": [
{
"name": "TableName",
"value": "T_IOT_PROCESSING_SERVICE_CONFIG",
"namespace": "com.sap.iotservices.mms"
}
]
}
],
"extensions": [
{
"name": "SchemaName",
"value": "DEMO",
"namespace": "com.sap.iotservices.mms"
}
]
}
]
}
]
}
}
Hi,
Thanks for reporting the issue. i reproduced the issue in this jsbin Tracked internally 1680215895
best regards, Tobias
Hi, refreshMetadata should only be used if the metadata request fails. In all other cases the application needs a restart, as the refresh does not reload annotations and does not retrigger a rerendering of the application. This could lead to data inconsistency and invalid UIs. I adapted the documentation. BR, Jan
What is meant by restart? With our UI the user is able to create tables and adding items to that table during runtime which means that the OData metadata changes as the user uses our frontend. Whats the common way to reload these annotations?