Potential Bug in OData Model
OpenUI5 version: 1.68.1
Browser/version (+device/version): Version 75.0.3770.142 (Offizieller Build) (64-Bit)
URL (minimal example if possible): https://ecubed-solutions.ddnss.de/#/Input/SelectFood/CustomProducts
If you switch to debug console, use mobile phone and reload to adapt for new format (has nothing to do with bug, just look :))
User/password (if required and possible - do not post any confidential information here): User: sap Password sap
Steps to reproduce the problem:
- Open developer tools, go to file Controller/Input/CustomProducts.controller.js
- Set breakpoint at line 86 and reload page
- Please look at oContext, the path is wrong:
What is the expected result? /Account(3)/UserDefinedProducts_fKUserDefinedProductToAccount(657897)
What happens instead? Path is /Account(3)/UserDefinedProducts_fKUserDefinedProductToAccount/-9007199254740991"
Any other information? (attach screenshot if possible)
Hello Mathias (@uhlmannm) and Thomas (@ThomasChadzelek), I am currently trying to follow your recommendation to use a single context for my bindings for data reuse. My views architecture looks as follows. I have a main view, which wraps all my other views. The main view is given as
<mvc:View controllerName="mnd.controller.Main"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns:l="sap.ui.layout"
xmlns="sap.m" id="idMainView">
<!-- idApp is the main view container which displays all pages. Navigation is controlled via SAPUI5 router -->
<App id="idApp" busy="{AppStateModel>/bAppIsBusy}" backgroundImage="resources/images/vert1.jpg" backgroundOpacity="0.5" class="mndCustomStyle" height="calc(100% - 48px)"/>
<!-- bottum menubar section -->
<Bar id="idFooterBar" class="sapContrast sapContrastPlus sapMBar sapMBar-CTX sapMContent-CTX sapMFooter-CTX sapMIBar sapMIBar-CTX">
<contentMiddle>
<Button width="20%" icon="sap-icon://blur" enabled="{= ${AppStateModel>/bAppIsBusy} === false}" press="onAddLiquidPressed"/>
<Button width="20%" icon="sap-icon://camera" enabled="{= ${AppStateModel>/bAppIsBusy} === false}" press="onOpenCameraDialogPressed"/>
</contentMiddle>
</Bar>
</mvc:View>
In its controller I bind the root of my odata model as context to the App
var oApp = this.byId("idApp");
oApp.bindElement({path: "/Account(" + AppStateSingleton.iProfileID + ")"
});
The list which I try to fill with a factory function for items is given in the wrapped child view and looks as follows
<List id="idCustomProductsList"
mode="SingleSelectMaster"
itemPress="onItemPressed"
items="{path: 'UserDefinedProducts_fKUserDefinedProductToAccount', factory: '.createListItemFactory'}">
<dependents>
<core:Fragment fragmentName="mnd.view.UserDefinedProductListItem"
type="XML" />
</dependents>
</List>
The factory function is given as below. It clones a fragment that represents a list item:
createListItemFactory: function(sId, oContext) {
// clone user defined product list item template
return this.byId("idUserDefinedProductListItem").clone(sId);
},
And finally the relevant fragment which the factory clones is given as
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<CustomListItem id="idUserDefinedProductListItem" type="Active" class="sapMLIB sapMLIBHoverable">
<HBox justifyContent="SpaceBetween" alignItems="Center" class="sapUiTinyMarginBeginEnd sapUiTinyMarginTopBottom">
<VBox>
<Text text="{product_name}" class="mndLabelFont"/>
<HBox>
<Text text="{brands}, 100 g" class="mndGreyLabelFontColor"/>
</HBox>
</VBox>
<Text text="{path: 'energy_100g', formatter: '.oFormatter.displayKJasKCal'}" class="mndGreyLabelFontColor"/>
</HBox>
</CustomListItem>
</core:FragmentDefinition>
Do you see that I made a mistake somewhere? Or did I hit a bug here? I do not understand why the context in the ListItemFactory does not result in a valid path. Thanks for your help!
The odata model can be inspected here: The relevant product items to be shown https://ecubed-solutions.ddnss.de/odata4/svc/my_nutri_diary/UserDefinedProducts
and: https://ecubed-solutions.ddnss.de/odata4/svc/my_nutri_diary/$metadata
Hi cjohn001,
There's nothing wrong with this path. It actually results from the parameter 'autoExpandSelect' at the model. When this parameter is set, the bindings try to deduce which properties and entities are used in the view and build appropriate $select and $expand options for the query.
For a list binding this is relatively difficult, because this can only be decided when there is data in the list. So it temporarily adds a row using a "virtual" context, gathers the value requests from all property bindings in that row and adds their paths to $select/$expand. Then this virtual context is deleted again before the actual request starts.
If a table is built using a template, this template is applied for this "virtual" row, too. (If not, the autoExpandSelect mechanism would not work.) The context for this row is recognizable by the index -9007199254740991 (-Number.MIN_SAFE_INTEGER). And this is the context path that you saw.
Did you experience any problems with it or did you just wonder?
Regards, Uwe
Hello Uwe,
Did you experience any problems with it or did you just wonder?
Yes, I am experiencing problems. This was what the example I provided shall show. Seems then the issue is not related to the index value directly. However, from the example I provided you can see my problem. The list should show up 1 list item, but it does show an empty list instead. The factory function is called once ( I was assuming for the one list item that should be created), but the factory function is called with the index I mentioned and not with the correct one that is required to create the item. I described the steps to reproduce it. Please have a look at it. Even so the index seems to be valid according to your description I am then still wondering why this index value is provided as a parameter to the lists factory function. I have never seen such an index value as a parameter to a factory function when list items are to be created. As this is strange, maybe this is the bug then?
Best regards, Christoph
Hi Christoph,
You're right, the factory function should not be called for the virtual context only, but for each row, too. I checked in our own test for it.
About your app:
There is no data in the table because it sends its request in a $batch preceded by 3 other requests of which the first one fails. So the table request itself is not even processed.
The failing request is "GET Account(3)/product_name" for which the server complains that the type does not have this property. This requests originates from a property binding with path "product_name" and a context for "Account(3)". This seems to be bound to a Text somewhere in the menu button with the "+".
Regards, Uwe
Hello Uwe,
$batch preceded by 3 other requests of which the first one fails.
These three requests derive from the same issue. You cannot see the view xml in the sources therefore you probably have guessed this. Let me explain.
"GET Account(3)/product_name" and the following two request result from the list item template on which the single list item I mentioned should be created. In the factory function you see that the item to be created is cloned from a fragment
createListItemFactory: function(sId, oContext) {
return this.byId("idUserDefinedProductListItem").clone(sId);
},
The fragment code looks as follows
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<CustomListItem id="idUserDefinedProductListItem" type="Active" class="sapMLIB sapMLIBHoverable">
<HBox justifyContent="SpaceBetween" alignItems="Center" class="sapUiTinyMarginBeginEnd sapUiTinyMarginTopBottom">
<VBox>
<Text text="{product_name}" class="mndLabelFont"/>
<HBox>
<Text text="{brands}, 100 g" class="mndGreyLabelFontColor"/>
</HBox>
</VBox>
<Text text="{path: 'energy_100g', formatter: '.oFormatter.displayKJasKCal'}" class="mndGreyLabelFontColor"/>
</HBox>
</CustomListItem>
</core:FragmentDefinition>
Here you see the 3 request that will fail for the three properties product_name, brands, energy_100g.
The failing request is "GET Account(3)/product_name" for which the server complains that the type does not have this property.
The correct path for the property product_name would be given as:
https://ecubed-solutions.ddnss.de/odata4/svc/my_nutri_diary/UserDefinedProducts(657897)/product_name
or via navigation property /Account(3)/UserDefinedProducts_fKUserDefinedProductToAccount(657897)/product_name
The parent context points to Account(3) which is correct in this case, as this is the context that all my views should reuse.
The list view binds the collection with the fragment in the following way:
<List id="idCustomProductsList"
mode="SingleSelectMaster"
itemPress="onItemPressed"
items="{path: 'UserDefinedProducts_fKUserDefinedProductToAccount', factory: '.createListItemFactory'}">
<dependents>
<core:Fragment fragmentName="mnd.view.UserDefinedProductListItem"
type="XML" />
</dependents>
</List>
So this should result in the missing part of the path "'/UserDefinedProducts_fKUserDefinedProductToAccount(657897)"
So my assumption then is, that the auto-expand than does not correctly infer the path for the properties used in the fragment. Might be that this is the underlaying error?
So the table request itself is not even processed.
You can set a breakpoint into the factory function and will see, that the request is processed
Have you any ideas why the path inference for the properties bound in the fragment than fails?
Best regards, Christoph
Hi Christoph,
There are two property bindings with the path "product_name" created in your app. The first one is for the virtual context in the list. And it works perfectly well as it adds "product_name" to the list's $select.
The second one has the context binding for "/Accounts(3)" created by the router as parent. It belongs to a Text in a CustomListItem in the list's customData. Obviously your fragment is part of the tree and UI5 creates bindings for it, too, using the page's context.

The same happens for "brands" and "energy_100g".
As a result the model creates a request for the account with the list's path expanded (and the list's three fields plus the key property selected):
"GET Account(3)?$select=idProfile&$expand=UserDefinedProducts_fKUserDefinedProductToAccount($select=brands,energy_100g,fkProduct,product_name)".
The three additional requests arise from the failure to include the bindings for the CustomData into this request because of metadata errors.
Try to move this CustomData somewhere else where it doesn't inherit from the Page. Or simply use a ColumnListItem instead of the factory function.
Regards, Uwe
Hello Uwe, thanks for analyzing. I am sorry, but I do not understand where you see the second binding. I triple checked the code now. This is my xml description
<ScrollContainer id="idScrollContainerCustomProducts"
width="100%"
horizontal="false"
vertical="true">
<List id="idCustomProductsList"
mode="SingleSelectMaster"
itemPress="onItemPressed"
items="{path: 'UserDefinedProducts_fKUserDefinedProductToAccount', factory: '.createListItemFactory'}">
<dependents>
<core:Fragment fragmentName="mnd.view.UserDefinedProductListItem"
type="XML" />
</dependents>
</List>
</ScrollContainer>
The CustomData in your screenshot called (CustomData-__data6) which you are seeing on the list is nothing which I defined on the view or in my javascript code.
The second one has the context binding for "/Accounts(3)" created by the router as parent. It belongs to a Text in a CustomListItem in the list's customData. Obviously your fragment is part of the tree and UI5 creates bindings for it, too, using the page's context.
So is
<dependents>
<core:Fragment fragmentName="mnd.view.UserDefinedProductListItem"
type="XML" />
</dependents>
responsable for the CustomData that are added to the list? As far as I understood from the tutorials, this is exately how I have to include the dependency to the view. Is this wrong? And how would I than do it right?
Regarding the element you marked in the control tree view: This is exactly resulting from the fragment above. As I need it as a template to clone for the list elements, to my understanding I need it here as a dependency.
The failing request is "GET Account(3)/product_name" for which the server complains that the type does not have this property. This requests originates from a property binding with path "product_name" and a context for "Account(3)". This seems to be bound to a Text somewhere in the menu button with the "+".
I forgot to answer this in your recent comment. The menu button uses the custom data, but it does not hold a binding to the odata context
<MenuButton buttonMode="Split"
icon="sap-icon://add"
defaultAction=".onAddCustomProduct"
class="sapUiTinyMarginBegin">
<menu>
<Menu app:ShowEditCustomProductsState="false"
app:ShowDeleteCustomProductState="false"
itemSelected=".onMenuAction"
closed=".onMenuClosed">
<items>
<MenuItem key="AddCustomProducts"
text="{i18n>strAddCustomProduct}"
icon="sap-icon://add" />
<MenuItem key="EditCustomProducts"
text="{i18n>strEditCustomProducts}"
icon="sap-icon://edit" />
<MenuItem key="DeleteCustomProducts"
text="{i18n>strShowDeleteCustomProducts}"
icon="sap-icon://delete" />
</items>
</Menu>
</menu>
<layoutData>
<FlexItemData growFactor="0" />
</layoutData>
</MenuButton>
Try to move this CustomData somewhere else where it doesn't inherit from the Page. Or simply use a ColumnListItem instead of the factory function.
I do not understand your suggestion and which CustomData you are meaning. The custom data from the MenuButton cannot be the cause as you can see. And from the list, the CustomData seem to be from the control itself and not from my view definition. Could you please go into more detail? Thanks!
Hello Christoph,
sorry for the delay.
Yes, the Fragment in the dependents is the cause for these unwanted bindings. The documentation for the aggregation 'dependents' in 'sap.m.List' states:
Dependents are not rendered, but their databinding context and lifecycle are bound to the aggregating Element.
And the aggregating element is the list which inherits a binding context for "/Accounts(3)" from the page, set by the router. For this reason it is possible to use a relative binding for the list.
You could try the following: Give the Fragment the id="fragment" and add the following code into onInit:
this.oView.byId("fragment").setBindingContext(null);
This should prevent that the fragment inherits a binding context. Then no bindings should be created for the fragment anymore.
The problem is in fact specific to OData V4, as only here these property bindings will actively trigger requests and run into problems. We're currently discussing how to deal with this better.
Regards, Uwe
Hello Uwe, thanks for your feedback. Your recommendation put me on the right track, and the workaround is ok now. The solution looks similar to your description. I document it here in case others run into the same issue. The difference to your described approach is, that it seems like the Fragment itself is not instantiated but rather the controls in the fragment. Hence, the binding context of the contained controls (in my example a ListItem called "idUserDefinedProductListItem") in the fragment needs to be bound to null:
var oProductListItemTemplate = this.getView().byId(sap.ui.core.Fragment.createId("fragment", "idUserDefinedProductListItem")); oProductListItemTemplate.setBindingContext(null);
Are you planning to do some changes regarding the issue? Hence, should we leave the issue open for further reference?
Best regards, Christoph
Adding this for the record #1980390256
Hi Christoph,
the V4 property bindings behavior is delivered since a long time and cannot be changed in a compatible way. Hence we will not change something.
Best regards Mathias.