openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

oData v4 list grouping issue with empty context

Open hschaefer123 opened this issue 6 years ago • 11 comments

OpenUI5 version: 1.71.19

Browser/version (+device/version): chrome

Steps to reproduce the problem:

Inside a table i am using grouping

<Table id="CartTable" "
		items="{
			path: '/CartItems',
			parameters: {
				$$updateGroupId : 'CartGroup',
				$select : 'Supplier_Supplier',	
				$expand: 'Supplier',
				$count : true
			},
			sorter: [
				{ path: 'Supplier_Supplier', descending: false, group: true, xgroup: '.getSupplierName'},
				{ path: 'date'}
			],
			templateShareable: false
		}">

i got an error

ODataListBinding-dbg.js:1411 Uncaught (in promise) TypeError: Cannot read property 'slice' of undefined
    at ODataListBinding-dbg.js:1411

The error is, that.oModel.resolve(that.sPath, that.oContext) is null/undefined

			}).catch(function (oError) {
				that.oModel.reportError("Failed to get contexts for "
						+ that.oModel.sServiceUrl
						+ that.oModel.resolve(that.sPath, that.oContext).slice(1)
						+ " with start index " + iStart + " and length " + iLength,
					sClassName, oError);
			});

and only the first list/table entry was grouped.

Inside grouper function, there is only a bound context for one entry.

I also figured out that this happens only in conjunction with my inline relative binding to select possible units inside shopping cart.

<l:HorizontalLayout>
	<StepInput width="7rem" value="{Quantity}" change=".onCalculateCart"/>	
	<Select class="sapUiTinyMarginBegin bonUiMSltDisabledText" width="6rem" selectedKey="{Unit_UnitOfMeasure}" forceSelection="false" enabled="{= %{Product/Units/$count} > 1 }"
		items="{
			path: 'Product/Units',
			templateShareable: false
		}">
		<core:Item key="{AlternativeUnit_UnitOfMeasure}" text="{AlternativeUnit/UnitOfMeasureLongName}{= ${QuantityNumerator} > 1 ? ' (' + ${QuantityNumerator} + ' ' + ${Product/BaseUnit_UnitOfMeasure} + ')' : ''}"/>							
	</Select>
</l:HorizontalLayout> 

If i comment out the relative aggregation binding, the grouper works as expected!

Since v4, getContext works sometimes async. Maybe grouper does not support this right now? I think, the relative binding "{Product/Unit}" forces internally async loading/handling of context and grouper seems to try to get data in sync. That would be the reason why only one context data is available at grouper access time.

I would need a fix in the LTS version.

Regards Holger

hschaefer123 avatar Jul 29 '20 15:07 hschaefer123

Hello @hschaefer123 , Thank you for sharing this finding. I've created an internal incident 2080321417. The status of the issue will be updated here in GitHub. Regards, Florian

flovogt avatar Jul 30 '20 13:07 flovogt

Dear @hschaefer123 , I was not able to reproduce this issue, but the error you mentioned is thrown while reporting an error, maybe you can sent us the Values of sPath and oContext

I think the interesting thing is oContext it should not be empty. (Edit: sry forget it you have done this already :-) )

A complete callstack would also be helpfull.

Other thing I cannot see at the moment: Supplier_Supplier is part of the table? Or are you trying to sort a not visible Property?

Best regards Alex

alexanderriess avatar Aug 03 '20 11:08 alexanderriess

Hi Alexander, ist it possible, that you send me privately you S-USER and corresponding email address via private message, so that i can add it to CF?

The CAP cart service is running authenticated only, and then you would be able to access the whole mock app.

Then you would be able to use sap idp to authenticate and can investigate the error directly.

If this is not possible, let me know! I will try to add a public route with the given error scenario.

Supplier_Supplier is expanded (see cartItem) $select : 'Supplier_Supplier', $expand: 'Supplier',

But this works alone side. Starting adding Units relatively, the data is part of the return, but i think odata v4 is switching to async getProperty.

CAP CDS

entity CartItems : cuid {
    user                  : User;
    date                  : DateTime;
    Product               : Association to Products not null;
    Supplier              : Association to Suppliers not null;
    Quantity              : Decimal(9, 2);
    Unit                  : Association to UnitOfMeasures;
    RequestedDeliveryDate : Date;
}

/* I_Product from mara, I_ProductText from makt */
entity Products : managed {
    key Product                    : String(40); // Product Number
        ProductExternalID          : String(40); // External Representation of Material Number
        ProductName                : localized String(40); // Product Description
        //Description            : localized String(40);
        DescriptionAdditional      : localized String(255);
        Units                      : Composition of many ProductUnitsOfMeasures
                                         on Units.Product = $self;
        BaseUnit                   : Association to UnitOfMeasures; // Base Unit of Measure
        Catalog                    : Association to Catalogs;
        //ManufacturerNumber:   Association to Suppliers; // Manufacturer number
        Supplier                   : Association to Suppliers;
        SupplierMaterialNumber     : String(35);
        Price                      : Decimal(11, 2);
        PriceCurrency              : Currency;
        Quantity                   : Decimal(13, 3);
        StatusCriticality          : String(10);
        IsNew                      : Boolean;
        PickLocation               : String(4);
        //Tags                  : Composition of many Tags on Tags.Name = $self;
        ImageUrl                   : String; // @Core.IsURL  @Core.MediaType : imageType;
        ImageType                  : String @Core.IsMediaType;
        InternationalArticleNumber : String(18); // ???
}

/* I_ProductUnitsOfMeasure from marm */
entity ProductUnitsOfMeasures {
    key Product             : Association to Products; // Product Number
    key AlternativeUnit     : Association to UnitOfMeasures; // Alternative Unit of Measure for Stockkeeping Unit
        QuantityNumerator   : Decimal(5, 0); // Numerator for Conversion to Base Units of Measure
        QuantityDenominator : Decimal(5, 0); // Denominator for conversion to base units of measure
}

/* I_Supplier from lfa1 */
entity Suppliers : managed {
    key Supplier         : String(10); // Account Number of Vendor or Creditor
        SupplierName     : String(80); // Name of Supplier
        SupplierFullName : String(220); // Supplier Full Name
}

The shop is firing one request only

https://stzh-dev-services-webshop.cfapps.eu10.hana.ondemand.com/backend/shop/CartItems?$select=ID,Quantity,RequestedDeliveryDate,Supplier_Supplier,Unit_UnitOfMeasure&$expand=Product($select=BaseUnit_UnitOfMeasure,DescriptionAdditional,ImageUrl,PickLocation,Price,Product,ProductName;$expand=Supplier($select=Supplier,SupplierName),Units($select=AlternativeUnit_UnitOfMeasure,Product_Product,QuantityNumerator;$expand=AlternativeUnit($select=UnitOfMeasure,UnitOfMeasureLongName))),Supplier&$count=true&$orderby=Supplier_Supplier,date&$skip=0&$top=100

and the result contains all data

{"@odata.context":"$metadata#CartItems(ID,Quantity,RequestedDeliveryDate,Supplier_Supplier,Unit_UnitOfMeasure,Product(BaseUnit_UnitOfMeasure,DescriptionAdditional,ImageUrl,PickLocation,Price,Product,ProductName,Supplier(Supplier,SupplierName),Units(AlternativeUnit_UnitOfMeasure,Product_Product,QuantityNumerator,AlternativeUnit(UnitOfMeasure,UnitOfMeasureLongName))),Supplier())","@odata.count":"2","value":[{"ID":"500ecd81-37f6-4a37-b902-558eed57f207","Quantity":"1","RequestedDeliveryDate":null,"Supplier_Supplier":"FRL","Unit_UnitOfMeasure":"BD","Product":{"Product":"5005542","BaseUnit_UnitOfMeasure":"BD","DescriptionAdditional":"- Bund à 100 ST","ImageUrl":"/media/products/5005542.jpg","PickLocation":"SBMV","Price":"17","ProductName":"Holzstecketiketten 240 x 24 mm","Units":[{"Product_Product":"5005542","AlternativeUnit_UnitOfMeasure":"BD","QuantityNumerator":"1","AlternativeUnit":{"UnitOfMeasure":"BD","UnitOfMeasureLongName":"Bund"}}],"Supplier":{"Supplier":"FRL","SupplierName":"Flug Zürich"}},"Supplier":{"Supplier":"FRL","SupplierName":"Flug Zürich","SupplierFullName":"Flug Zürich"}},{"ID":"52217e81-1c89-44ac-9944-1999777d018d","Quantity":"1","RequestedDeliveryDate":null,"Supplier_Supplier":"GSZ","Unit_UnitOfMeasure":"ROL","Product":{"Product":"5004375","BaseUnit_UnitOfMeasure":"ROL","DescriptionAdditional":null,"ImageUrl":"/media/products/5004375.jpg","PickLocation":"SBMV","Price":"31.55","ProductName":"Kokos-Flachstrick 7-fach","Units":[{"Product_Product":"5004375","AlternativeUnit_UnitOfMeasure":"BD","QuantityNumerator":"12","AlternativeUnit":{"UnitOfMeasure":"BD","UnitOfMeasureLongName":"Bund"}},{"Product_Product":"5004375","AlternativeUnit_UnitOfMeasure":"FL","QuantityNumerator":"1","AlternativeUnit":{"UnitOfMeasure":"FL","UnitOfMeasureLongName":"Flasche"}},{"Product_Product":"5004375","AlternativeUnit_UnitOfMeasure":"ROL","QuantityNumerator":"24","AlternativeUnit":{"UnitOfMeasure":"ROL","UnitOfMeasureLongName":"Rolle"}},{"Product_Product":"5004375","AlternativeUnit_UnitOfMeasure":"STK","QuantityNumerator":"1","AlternativeUnit":{"UnitOfMeasure":"STK","UnitOfMeasureLongName":"Stück"}}],"Supplier":{"Supplier":"GSZ","SupplierName":"Grün Stadt Zürich"}},"Supplier":{"Supplier":"GSZ","SupplierName":"Grün Stadt Zürich","SupplierFullName":"Grün Stadt Zürich"}}]}

Regards Holger

hschaefer123 avatar Aug 03 '20 16:08 hschaefer123

Only first (or at least one ) group is handled correctly and returning context data.

v4issuewithgroup

Removing "{Product/Units}" relative unit selector, everthing works fine.

v4gorupissueok

Regards Holger

hschaefer123 avatar Aug 04 '20 13:08 hschaefer123

Hi can you please copy us the call stack of the error message? I think also that there is a problem with the async call of getContexts, but I'm not sure where I can dispatch this message... This would help a lot :-) thank you

alexanderriess avatar Aug 04 '20 14:08 alexanderriess

This is the stack trace from inside the catch just before that.oModel.reportError.

Let me know, if you need more...

(anonymous) (ODataListBinding-dbg.js:1409)
Promise.catch (async)
l.getContexts (ODataListBinding-dbg.js:1408)
o.refreshAggregation (ManagedObject-dbg.js:4124)
d.refreshItems (SelectList-dbg.js:254)
t.refreshItems (Select-dbg.js:744)
A.refresh (ManagedObjectMetadata-dbg.js:394)
w (ManagedObject-dbg.js:3850)
b.fireEvent (EventProvider-dbg.js:243)
B._fireRefresh (Binding-dbg.js:566)
l.reset (ODataListBinding-dbg.js:2122)
(anonymous) (ODataListBinding-dbg.js:1356)
(anonymous) (Core-dbg.js:4012)
Core.runPrerenderingTasks (Core-dbg.js:4011)
Core.renderPendingUIUpdates (Core-dbg.js:2705)
setTimeout (async)
Core.addInvalidatedUIArea (Core-dbg.js:2650)
U.addInvalidatedControl (UIArea-dbg.js:520)
c.invalidate (Control-dbg.js:329)
o.setParent (ManagedObject-dbg.js:2662)
o.addAggregation (ManagedObject-dbg.js:2180)
(anonymous) (XMLTemplateProcessor-dbg.js:519)
Promise.then (async)
(anonymous) (XMLTemplateProcessor-dbg.js:515)
Promise.then (async)
S.then (SyncPromise-dbg.js:312)
H (XMLTemplateProcessor-dbg.js:512)
I (XMLTemplateProcessor-dbg.js:558)
n (XMLTemplateProcessor-dbg.js:411)
X.parseTemplatePromise (XMLTemplateProcessor-dbg.js:266)
k.onControllerConnected (XMLView-dbg.js:636)
F (View-dbg.js:486)
r (Component-dbg.js:201)
p.runAsOwner (Component-dbg.js:602)
P (View-dbg.js:470)
(anonymous) (View-dbg.js:498)
Promise.then (async)
f._initCompositeSupport (View-dbg.js:497)
(anonymous) (ManagedObject-dbg.js:534)
constructor (ManagedObject-dbg.js:558)
constructor (Element-dbg.js:151)
constructor (Control-dbg.js:175)
f (Metadata-dbg.js:463)
f (Metadata-dbg.js:463)
w (View-dbg.js:1133)
v (View-dbg.js:1097)
c.createContent (UIComponent-dbg.js:565)
createContent (Component.js:154)
(anonymous) (UIComponent-dbg.js:324)
o.runWithPreprocessors (ManagedObject-dbg.js:1043)
(anonymous) (UIComponent-dbg.js:323)
r (Component-dbg.js:201)
p.runAsOwner (Component-dbg.js:602)
c.init (UIComponent-dbg.js:322)
init (Component.js:75)
(anonymous) (ManagedObject-dbg.js:539)
constructor (ManagedObject-dbg.js:558)
constructor (Component-dbg.js:293)
constructor (UIComponent-dbg.js:81)
f (Metadata-dbg.js:463)
i1 (Component-dbg.js:2612)
A (Component-dbg.js:2210)
(anonymous) (Component-dbg.js:2263)
r (Component-dbg.js:201)
(anonymous) (Component-dbg.js:2262)
Promise.then (async)
y (Component-dbg.js:2261)
p.create (Component-dbg.js:2076)
i (Component-dbg.js:1194)
p._createComponent (Component-dbg.js:1205)
e._createComponent (ComponentContainer-dbg.js:311)
e.onBeforeRendering (ComponentContainer-dbg.js:330)
d._handleEvent (Element-dbg.js:286)
Z (RenderManager-dbg.js:757)
R.renderControl (RenderManager-dbg.js:868)
R.render (RenderManager-dbg.js:1246)
U.rerender (UIArea-dbg.js:629)
Core.renderPendingUIUpdates (Core-dbg.js:2710)
setTimeout (async)
Core.addInvalidatedUIArea (Core-dbg.js:2650)
U.addInvalidatedControl (UIArea-dbg.js:520)
U.invalidate (UIArea-dbg.js:499)
o.setParent (ManagedObject-dbg.js:2662)
o.addAggregation (ManagedObject-dbg.js:2180)
U.addContent (UIArea-dbg.js:357)
(anonymous) (Interface-dbg.js:57)
c.placeAt (Control-dbg.js:657)
f.run (ComponentSupport-dbg.js:70)
(anonymous) (ComponentSupport-dbg.js:169)
(anonymous) (ui5loader-dbg.js:1785)
Promise.then (async)
requireAll (ui5loader-dbg.js:1703)
executeModuleDefinition (ui5loader-dbg.js:1759)
(anonymous) (ui5loader-dbg.js:1212)
ModuleDefinitionQueue.process (ui5loader-dbg.js:1210)
execModule (ui5loader-dbg.js:1627)
requireModule (ui5loader-dbg.js:1420)
requireAll (ui5loader-dbg.js:1693)
r (ui5loader-dbg.js:1949)
(anonymous) (bootstrap.js:49)
(anonymous) (ui5loader-dbg.js:1785)
Promise.then (async)
requireAll (ui5loader-dbg.js:1703)
executeModuleDefinition (ui5loader-dbg.js:1759)
(anonymous) (ui5loader-dbg.js:1212)
ModuleDefinitionQueue.process (ui5loader-dbg.js:1210)
o (ui5loader-dbg.js:1301)
load (async)
loadScript (ui5loader-dbg.js:1335)
requireModule (ui5loader-dbg.js:1537)
requireAll (ui5loader-dbg.js:1693)
r (ui5loader-dbg.js:1949)
setTimeout (async)
Core._executeOnInit (Core-dbg.js:1252)
Core._executeInitialization (Core-dbg.js:1365)
Core.init (Core-dbg.js:1195)
(anonymous) (Core-dbg.js:483)
a (Core-dbg.js:177)
SyncPoint.finishTask (Core-dbg.js:171)
(anonymous) (Core-dbg.js:506)
(anonymous) (Core-dbg.js:865)
Promise.then (async)
Core._boot (Core-dbg.js:864)
(anonymous) (Core-dbg.js:505)
a (Core-dbg.js:177)
SyncPoint.finishTask (Core-dbg.js:171)
(anonymous) (Core-dbg.js:580)
Promise.then (async)
constructor (Core-dbg.js:579)
(anonymous) (Core-dbg.js:4099)
(anonymous) (ui5loader-dbg.js:1785)
requireAll (ui5loader-dbg.js:1708)
executeModuleDefinition (ui5loader-dbg.js:1759)
ui5Define (ui5loader-dbg.js:1891)
execModule (ui5loader-dbg.js:1580)
requireModule (ui5loader-dbg.js:1420)
requireSync (ui5loader-dbg.js:2018)
(anonymous) (jquery-mobile-custom-dbg.js:2106)

hschaefer123 avatar Aug 04 '20 14:08 hschaefer123

Hi @hschaefer123,

Having access to your app would probably be helpful, but private messages are not possible in GitHub any longer.

Some more questions that I would like to ask:

Throwing an error in the error handling is surely embarrassing and we'll fix that. But for now could you please tell us the error that has been caught before and that the code was trying to report including its stack trace? Can you also look up the path of the binding (that.sPath)?

I presume that it is not the grouping, but the list binding for the drop down of the connected to the table? It has a relative binding which needs a context to an instance of ProductUnitsOfMeasures, so it must somehow been supplied with some binding context?

Do you use autoExpandSelect at the model?

Regards, Uwe

UweReeder avatar Aug 07 '20 13:08 UweReeder

Hi, after some refactoring, i created a public route for displaying the error.

OpenUI5 1.71.19 https://stzh-dev-services-webshop.cfapps.eu10.hana.ondemand.com/public/index.html#/checkout/cart

I created a second index2.html with using latest openui5 nightly version.

OpenUI5 1.82.x https://stzh-dev-services-webshop.cfapps.eu10.hana.ondemand.com/public/index2.html#/checkout/cart

and the grouping is shown correctly, but open Diagnostics changing the log level, i still see the slice error for each item?!?

For my project, i can wait for the upcomming next LTS version 1.83/84?

If SAP will not be able to deliver v4 in ABAP restful 2009 release we have to fallback to v2, but then i will try to use v4 model with v2 adapter.

Anyhow, it would be great to get important core/model fixes backported to current LTS version, because for productive customer projects, we generally stay on a stable base.

Thanks for the support on this.

Regards Holger

hschaefer123 avatar Aug 08 '20 14:08 hschaefer123

Thanks, that helped. We are able to reproduce this problem now. It seems to be a timing issue. In our tests the problem also occurs in master.

We are working on a fix.

Regards, Uwe

UweReeder avatar Aug 10 '20 15:08 UweReeder

Closed by bot correctly? Still bug.

Will you still post updates here?

Regards Holger

hschaefer123 avatar Aug 12 '20 07:08 hschaefer123

Oh, I was not aware of this bot.

I just submitted change f0a104eb2e8d114b28e0ea078f22c2a967d10713 to master that fixes this bug. The fix will then be part of release 1.82.0. Is that sufficient for you or do you need a downport?

Regards, Uwe

UweReeder avatar Aug 12 '20 07:08 UweReeder