spreadsheetimporter / ui5-cc-spreadsheetimporter

A UI5 Component to integrate a Spreadsheet Upload for UI5 Apps.
https://spreadsheet-importer.com/
Apache License 2.0
82 stars 16 forks source link

[Bug]: The key value is already in use. Please enter a different one. #509

Closed sindhumogare closed 5 months ago

sindhumogare commented 7 months ago

OData Version

OData V2

Draft

Yes

Scenario

Fiori Elements

Environment

BAS

UI5 Spreadsheet Component

cc.spreadsheetimporter.v0_32_0

What happened?

I am using this component to upload my data which is in a spreadsheet from my presentation server. According to the logic required, when I upload the data, I validate it in the backend RAP Application. On receiving error in the backend for the first time, the spreadsheet component is giving the correct error. When I correct the data in the spreadsheet and try to re-upload the excel spreadsheet through the component, it throws the error: "The key value is already in use. Please enter a different one."

Request your urgent help on this issue.

Best Regards, Sindhu Mogare

Relevant log output

2024-03-01 18:56:11.088199 Request failed with status code 400: POST Qual_lvl?sap-client=011 - Another request in the same change set failed sap.ui.model.odata.ODataMessageParser
g @ Log-dbg.js:452
n.error @ Log-dbg.js:232
l._logErrorMessages @ ODataMessageParser-dbg.js:735
l.parse @ ODataMessageParser-dbg.js:177
$._parseResponse @ ODataModel-dbg.js:7725
$._handleError @ ODataModel-dbg.js:4768
$._processError @ ODataModel-dbg.js:4481
u @ ODataModel-dbg.js:3627
h @ ODataModel-dbg.js:3685
u @ ODataModel-dbg.js:3398
(anonymous) @ ODataModel-dbg.js:7471
(anonymous) @ datajs-dbg.js:1637
y @ datajs-dbg.js:2542
XMLHttpRequest.send (async)
request @ datajs-dbg.js:2592
Sr @ datajs-dbg.js:1615
n.request @ datajs-dbg.js:7957
$._request @ ODataModel-dbg.js:7477
g @ ODataModel-dbg.js:3485
(anonymous) @ ODataModel-dbg.js:3446
Promise.then (async)
p @ ODataModel-dbg.js:3441
$._submitRequest @ ODataModel-dbg.js:3505
$._submitBatchRequest @ ODataModel-dbg.js:3741
(anonymous) @ ODataModel-dbg.js:4162
r @ each-dbg.js:61
$._processRequestQueue @ ODataModel-dbg.js:4112
(anonymous) @ ODataModel-dbg.js:6203
Promise.then (async)
$.submitChanges @ ODataModel-dbg.js:6154
(anonymous) @ ODataV2-dbg.js:71
a @ ODataV2-dbg.js:70
e @ ODataV2-dbg.js:82
e @ OData-dbg.js:67
await in e (async)
(anonymous) @ SpreadsheetUploadDialog-dbg.js:188
i @ SpreadsheetUploadDialog-dbg.js:187
s @ CommonUtils-dbg.js:1113
c @ CommonUtils-dbg.js:1127
A @ Application-dbg.js:124
pe @ CommonUtils-dbg.js:1136
securedExecution @ ExtensionAPI-dbg.js:145
e @ SpreadsheetUploadDialog-dbg.js:213
await in e (async)
i.fireEvent @ EventProvider-dbg.js:247
d.fireEvent @ Element-dbg.js:627
(anonymous) @ ManagedObjectMetadata-dbg.js:799
B.ontap @ Button-dbg.js:580
d._handleEvent @ Element-dbg.js:343
_._handleEvent @ UIArea-dbg.js:961
dispatch @ jquery-dbg.js:5430
c @ jquery-mobile-custom-dbg.js:1899
h @ jquery-mobile-custom-dbg.js:2019
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
trigger @ jquery-dbg.js:8823
(anonymous) @ jquery-dbg.js:8901
each @ jquery-dbg.js:385
each @ jquery-dbg.js:207
trigger @ jquery-dbg.js:8900
j @ jquery-mobile-custom-dbg.js:1455
L @ jquery-mobile-custom-dbg.js:1465
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
Log-dbg.js:452 2024-03-01 18:56:11.094100 Request failed with status code 400: POST Qual_lvl?sap-client=011 - [{"code":"MC_CSP_USR_RUNTIME/006","message":"The key value is already in use. Please enter a different one.","persistent":true,"targets":["/Qual_lvl('id-1709296305535-182')"],"type":"Error"}] sap.ui.model.odata.ODataMessageParser
g @ Log-dbg.js:452
n.error @ Log-dbg.js:232
l._logErrorMessages @ ODataMessageParser-dbg.js:735
l.parse @ ODataMessageParser-dbg.js:177
$._parseResponse @ ODataModel-dbg.js:7725
$._handleError @ ODataModel-dbg.js:4768
$._processError @ ODataModel-dbg.js:4481
u @ ODataModel-dbg.js:3627
h @ ODataModel-dbg.js:3685
u @ ODataModel-dbg.js:3398
(anonymous) @ ODataModel-dbg.js:7471
(anonymous) @ datajs-dbg.js:1637
y @ datajs-dbg.js:2542
XMLHttpRequest.send (async)
request @ datajs-dbg.js:2592
Sr @ datajs-dbg.js:1615
n.request @ datajs-dbg.js:7957
$._request @ ODataModel-dbg.js:7477
g @ ODataModel-dbg.js:3485
(anonymous) @ ODataModel-dbg.js:3446
Promise.then (async)
p @ ODataModel-dbg.js:3441
$._submitRequest @ ODataModel-dbg.js:3505
$._submitBatchRequest @ ODataModel-dbg.js:3741
(anonymous) @ ODataModel-dbg.js:4162
r @ each-dbg.js:61
$._processRequestQueue @ ODataModel-dbg.js:4112
(anonymous) @ ODataModel-dbg.js:6203
Promise.then (async)
$.submitChanges @ ODataModel-dbg.js:6154
(anonymous) @ ODataV2-dbg.js:71
a @ ODataV2-dbg.js:70
e @ ODataV2-dbg.js:82
e @ OData-dbg.js:67
await in e (async)
(anonymous) @ SpreadsheetUploadDialog-dbg.js:188
i @ SpreadsheetUploadDialog-dbg.js:187
s @ CommonUtils-dbg.js:1113
c @ CommonUtils-dbg.js:1127
A @ Application-dbg.js:124
pe @ CommonUtils-dbg.js:1136
securedExecution @ ExtensionAPI-dbg.js:145
e @ SpreadsheetUploadDialog-dbg.js:213
await in e (async)
i.fireEvent @ EventProvider-dbg.js:247
d.fireEvent @ Element-dbg.js:627
(anonymous) @ ManagedObjectMetadata-dbg.js:799
B.ontap @ Button-dbg.js:580
d._handleEvent @ Element-dbg.js:343
_._handleEvent @ UIArea-dbg.js:961
dispatch @ jquery-dbg.js:5430
c @ jquery-mobile-custom-dbg.js:1899
h @ jquery-mobile-custom-dbg.js:2019
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
trigger @ jquery-dbg.js:8823
(anonymous) @ jquery-dbg.js:8901
each @ jquery-dbg.js:385
each @ jquery-dbg.js:207
trigger @ jquery-dbg.js:8900
j @ jquery-mobile-custom-dbg.js:1455
L @ jquery-mobile-custom-dbg.js:1465
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
Log-dbg.js:452 2024-03-01 18:56:11.110699 Request failed with status code 400: POST Qual_lvl?sap-client=011 - [{"code":"MC_CSP_USR_RUNTIME/006","message":"The key value is already in use. Please enter a different one.","persistent":true,"targets":["/Qual_lvl('id-1709297014234-298')"],"type":"Error"}] sap.ui.model.odata.ODataMessageParser
g @ Log-dbg.js:452
n.error @ Log-dbg.js:232
l._logErrorMessages @ ODataMessageParser-dbg.js:735
l.parse @ ODataMessageParser-dbg.js:177
$._parseResponse @ ODataModel-dbg.js:7725
$._handleError @ ODataModel-dbg.js:4768
$._processError @ ODataModel-dbg.js:4481
u @ ODataModel-dbg.js:3627
h @ ODataModel-dbg.js:3685
u @ ODataModel-dbg.js:3398
(anonymous) @ ODataModel-dbg.js:7471
(anonymous) @ datajs-dbg.js:1637
y @ datajs-dbg.js:2542
XMLHttpRequest.send (async)
request @ datajs-dbg.js:2592
Sr @ datajs-dbg.js:1615
n.request @ datajs-dbg.js:7957
$._request @ ODataModel-dbg.js:7477
g @ ODataModel-dbg.js:3485
(anonymous) @ ODataModel-dbg.js:3446
Promise.then (async)
p @ ODataModel-dbg.js:3441
$._submitRequest @ ODataModel-dbg.js:3505
$._submitBatchRequest @ ODataModel-dbg.js:3741
(anonymous) @ ODataModel-dbg.js:4162
r @ each-dbg.js:61
$._processRequestQueue @ ODataModel-dbg.js:4112
(anonymous) @ ODataModel-dbg.js:6203
Promise.then (async)
$.submitChanges @ ODataModel-dbg.js:6154
(anonymous) @ ODataV2-dbg.js:71
a @ ODataV2-dbg.js:70
e @ ODataV2-dbg.js:82
e @ OData-dbg.js:67
await in e (async)
(anonymous) @ SpreadsheetUploadDialog-dbg.js:188
i @ SpreadsheetUploadDialog-dbg.js:187
s @ CommonUtils-dbg.js:1113
c @ CommonUtils-dbg.js:1127
A @ Application-dbg.js:124
pe @ CommonUtils-dbg.js:1136
securedExecution @ ExtensionAPI-dbg.js:145
e @ SpreadsheetUploadDialog-dbg.js:213
await in e (async)
i.fireEvent @ EventProvider-dbg.js:247
d.fireEvent @ Element-dbg.js:627
(anonymous) @ ManagedObjectMetadata-dbg.js:799
B.ontap @ Button-dbg.js:580
d._handleEvent @ Element-dbg.js:343
_._handleEvent @ UIArea-dbg.js:961
dispatch @ jquery-dbg.js:5430
c @ jquery-mobile-custom-dbg.js:1899
h @ jquery-mobile-custom-dbg.js:2019
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
trigger @ jquery-dbg.js:8823
(anonymous) @ jquery-dbg.js:8901
each @ jquery-dbg.js:385
each @ jquery-dbg.js:207
trigger @ jquery-dbg.js:8900
j @ jquery-mobile-custom-dbg.js:1455
L @ jquery-mobile-custom-dbg.js:1465
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
Log-dbg.js:452 2024-03-01 18:56:11.111699 Request failed with status code 400: POST Qual_lvl?sap-client=011 - [{"code":"MC_CSP_USR_RUNTIME/006","message":"The key value is already in use. Please enter a different one.","persistent":true,"targets":["/Qual_lvl('id-1709297652547-411')"],"type":"Error"}] sap.ui.model.odata.ODataMessageParser
g @ Log-dbg.js:452
n.error @ Log-dbg.js:232
l._logErrorMessages @ ODataMessageParser-dbg.js:735
l.parse @ ODataMessageParser-dbg.js:177
$._parseResponse @ ODataModel-dbg.js:7725
$._handleError @ ODataModel-dbg.js:4768
$._processError @ ODataModel-dbg.js:4481
u @ ODataModel-dbg.js:3627
h @ ODataModel-dbg.js:3685
u @ ODataModel-dbg.js:3398
(anonymous) @ ODataModel-dbg.js:7471
(anonymous) @ datajs-dbg.js:1637
y @ datajs-dbg.js:2542
XMLHttpRequest.send (async)
request @ datajs-dbg.js:2592
Sr @ datajs-dbg.js:1615
n.request @ datajs-dbg.js:7957
$._request @ ODataModel-dbg.js:7477
g @ ODataModel-dbg.js:3485
(anonymous) @ ODataModel-dbg.js:3446
Promise.then (async)
p @ ODataModel-dbg.js:3441
$._submitRequest @ ODataModel-dbg.js:3505
$._submitBatchRequest @ ODataModel-dbg.js:3741
(anonymous) @ ODataModel-dbg.js:4162
r @ each-dbg.js:61
$._processRequestQueue @ ODataModel-dbg.js:4112
(anonymous) @ ODataModel-dbg.js:6203
Promise.then (async)
$.submitChanges @ ODataModel-dbg.js:6154
(anonymous) @ ODataV2-dbg.js:71
a @ ODataV2-dbg.js:70
e @ ODataV2-dbg.js:82
e @ OData-dbg.js:67
await in e (async)
(anonymous) @ SpreadsheetUploadDialog-dbg.js:188
i @ SpreadsheetUploadDialog-dbg.js:187
s @ CommonUtils-dbg.js:1113
c @ CommonUtils-dbg.js:1127
A @ Application-dbg.js:124
pe @ CommonUtils-dbg.js:1136
securedExecution @ ExtensionAPI-dbg.js:145
e @ SpreadsheetUploadDialog-dbg.js:213
await in e (async)
i.fireEvent @ EventProvider-dbg.js:247
d.fireEvent @ Element-dbg.js:627
(anonymous) @ ManagedObjectMetadata-dbg.js:799
B.ontap @ Button-dbg.js:580
d._handleEvent @ Element-dbg.js:343
_._handleEvent @ UIArea-dbg.js:961
dispatch @ jquery-dbg.js:5430
c @ jquery-mobile-custom-dbg.js:1899
h @ jquery-mobile-custom-dbg.js:2019
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
trigger @ jquery-dbg.js:8823
(anonymous) @ jquery-dbg.js:8901
each @ jquery-dbg.js:385
each @ jquery-dbg.js:207
trigger @ jquery-dbg.js:8900
j @ jquery-mobile-custom-dbg.js:1455
L @ jquery-mobile-custom-dbg.js:1465
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
Log-dbg.js:452 2024-03-01 18:56:11.112899 Request failed with status code 400: POST Qual_lvl?sap-client=011 - [{"code":"MC_CSP_USR_RUNTIME/006","message":"The key value is already in use. Please enter a different one.","persistent":true,"targets":["/Qual_lvl('id-1709298364297-530')"],"type":"Error"}] sap.ui.model.odata.ODataMessageParser
g @ Log-dbg.js:452
n.error @ Log-dbg.js:232
l._logErrorMessages @ ODataMessageParser-dbg.js:735
l.parse @ ODataMessageParser-dbg.js:177
$._parseResponse @ ODataModel-dbg.js:7725
$._handleError @ ODataModel-dbg.js:4768
$._processError @ ODataModel-dbg.js:4481
u @ ODataModel-dbg.js:3627
h @ ODataModel-dbg.js:3685
u @ ODataModel-dbg.js:3398
(anonymous) @ ODataModel-dbg.js:7471
(anonymous) @ datajs-dbg.js:1637
y @ datajs-dbg.js:2542
XMLHttpRequest.send (async)
request @ datajs-dbg.js:2592
Sr @ datajs-dbg.js:1615
n.request @ datajs-dbg.js:7957
$._request @ ODataModel-dbg.js:7477
g @ ODataModel-dbg.js:3485
(anonymous) @ ODataModel-dbg.js:3446
Promise.then (async)
p @ ODataModel-dbg.js:3441
$._submitRequest @ ODataModel-dbg.js:3505
$._submitBatchRequest @ ODataModel-dbg.js:3741
(anonymous) @ ODataModel-dbg.js:4162
r @ each-dbg.js:61
$._processRequestQueue @ ODataModel-dbg.js:4112
(anonymous) @ ODataModel-dbg.js:6203
Promise.then (async)
$.submitChanges @ ODataModel-dbg.js:6154
(anonymous) @ ODataV2-dbg.js:71
a @ ODataV2-dbg.js:70
e @ ODataV2-dbg.js:82
e @ OData-dbg.js:67
await in e (async)
(anonymous) @ SpreadsheetUploadDialog-dbg.js:188
i @ SpreadsheetUploadDialog-dbg.js:187
s @ CommonUtils-dbg.js:1113
c @ CommonUtils-dbg.js:1127
A @ Application-dbg.js:124
pe @ CommonUtils-dbg.js:1136
securedExecution @ ExtensionAPI-dbg.js:145
e @ SpreadsheetUploadDialog-dbg.js:213
await in e (async)
i.fireEvent @ EventProvider-dbg.js:247
d.fireEvent @ Element-dbg.js:627
(anonymous) @ ManagedObjectMetadata-dbg.js:799
B.ontap @ Button-dbg.js:580
d._handleEvent @ Element-dbg.js:343
_._handleEvent @ UIArea-dbg.js:961
dispatch @ jquery-dbg.js:5430
c @ jquery-mobile-custom-dbg.js:1899
h @ jquery-mobile-custom-dbg.js:2019
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
trigger @ jquery-dbg.js:8823
(anonymous) @ jquery-dbg.js:8901
each @ jquery-dbg.js:385
each @ jquery-dbg.js:207
trigger @ jquery-dbg.js:8900
j @ jquery-mobile-custom-dbg.js:1455
L @ jquery-mobile-custom-dbg.js:1465
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
Log-dbg.js:452 2024-03-01 18:56:30.648699 Error while calling the requestCompleted event - TypeError: Cannot read properties of undefined (reading 'bPreventDefault') SpreadsheetUpload: onUploadSet 
 TypeError: Cannot read properties of undefined (reading 'bPreventDefault')
    at Function.e [as fireEventAsync] (Util-dbg.js:215:18)
    at async t.e [as onUploadSet] (SpreadsheetUploadDialog-dbg.js:225:7)
g @ Log-dbg.js:452
n.error @ Log-dbg.js:232
e @ SpreadsheetUploadDialog-dbg.js:230
await in e (async)
i.fireEvent @ EventProvider-dbg.js:247
d.fireEvent @ Element-dbg.js:627
(anonymous) @ ManagedObjectMetadata-dbg.js:799
B.ontap @ Button-dbg.js:580
d._handleEvent @ Element-dbg.js:343
_._handleEvent @ UIArea-dbg.js:961
dispatch @ jquery-dbg.js:5430
c @ jquery-mobile-custom-dbg.js:1899
h @ jquery-mobile-custom-dbg.js:2019
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
trigger @ jquery-dbg.js:8823
(anonymous) @ jquery-dbg.js:8901
each @ jquery-dbg.js:385
each @ jquery-dbg.js:207
trigger @ jquery-dbg.js:8900
j @ jquery-mobile-custom-dbg.js:1455
L @ jquery-mobile-custom-dbg.js:1465
dispatch @ jquery-dbg.js:5430
y.handle @ jquery-dbg.js:5234
ODataV2-dbg.js:31 Uncaught (in promise)

Spreadsheet Component Init

"extensions": {
                "sap.ui.controllerExtensions": {
                    "sap.suite.ui.generic.template.ListReport.view.ListReport": {
                        "controllerName": "quallevel.ext.controller.ListReportExt",
                        "sap.ui.generic.app": {
                            "Qual_lvl": {
                                "EntitySet": "Qual_lvl",
                                "Actions": {
                                    "spreadsheetUpload": {
                                        "id": "spreadsheetUploadButton",
                                        "text": "Spreadsheet Upload",
                                        "press": "openSpreadsheetUploadDialog",
                                        "requiresSelection": false
                                    }
                                }
                            }
                        }
                    },
                    "sap.suite.ui.generic.template.ObjectPage.view.Details": {
                        "controllerName": "quallevel.ext.controller.ObjectPageExt",
                        "sap.ui.generic.app": {
                            "Qual_lvl": {
                                "EntitySet": "Qual_lvl",
                                "Header": {
                                    "Actions": {
                                        "spreadsheetUpload": {
                                            "id": "spreadsheetUploadButton",
                                            "text": "Spreadsheet Upload",
                                            "press": "openSpreadsheetUploadDialog",
                                            "requiresSelection": false
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

Manifest

"componentUsages": {
            "spreadsheetImporter": {
                "name": "cc.spreadsheetimporter.v0_32_0"
            }
        },
        "resourceRoots": {
            "cc.spreadsheetimporter.v0_32_0": "./thirdparty/customControl/spreadsheetImporter/v0_32_0"
        }
marianfoo commented 7 months ago

Hello @sindhumogare ,

Thanks for reaching out and creating this issue. Regarding Request your urgent help on this issue., as this is an open-source project, immediate support can be challenging to provide. However, I do offer paid consulting services for urgent assistance. If interested, please contact me directly to discuss rates and details.

Meanwhile, please ensure your issue report includes all necessary information to facilitate quicker community support. Are you using a on-premise system and with which version?

MARCxGAMBIT commented 7 months ago

@marianfoo I also wanted to create an issue concerning this topic. When an OData request fails because of an exception in the backend (RAP validation, BUSI_EXCEPTION etc) the changes are still pending in the model. Maybe you could add something like this somewhere after the request has been sent and response has been received (should work for both v2 and v4)?

if (oModel.hasPendingChanges()) {
    oModel.resetChanges();
}

I guess in this case it leads to all the entities being uploaded twice (the old pending changes and the re-up) thus generating the non unique key error.

marianfoo commented 7 months ago

I guess in this case it leads to all the entities being uploaded twice (the old pending changes and the re-up) thus generating the non unique key error.

I also suspect that it has something to do with that. I have a lot to do at the moment so I don't know when I'll get around to it.

MARCxGAMBIT commented 6 months ago

@sindhumogare @marianfoo quick workaround cold be adding a handler for requestCompleted (see https://docs.spreadsheet-importer.com/pages/Events/#event-when-the-request-is-completed) where one could do

const oModel = this.getView().getModel();
if (oModel.hasPendingChanges()) {
    oModel.resetChanges();
}
marianfoo commented 5 months ago

Hi @sindhumogare and @MARCxGAMBIT sorry for the long wait. Can you please check if this would fix it in #525 :

https://github.com/spreadsheetimporter/ui5-cc-spreadsheetimporter/blob/764dcced0e16503331eb60c9bd523d6bf0876291/packages/ui5-cc-spreadsheetimporter/src/controller/odata/OData.ts#L77-L88

marianfoo commented 5 months ago

fix was release with version 0.33.3, please check if that helped