Error when setting dynamic attribute through REST API

Hi,

We have a case in which we have defined a dynamic attribute as an enumeration with the ‘collection’ option enabled, so basically it is a multi-select field. This works fine within the UI but if we try to set this attribute through the REST API, it duplicates the options that have been set and as a result it cannot be edited from the UI anymore.

This behaviour has been seen in both release 7.1 and 7.2 of Cuba.

The attribute definition is like this (JSON export):

{
    "_entityName": "sys$CategoryAttribute",
    "id": "2541bcad-cd95-d42a-a2d7-a63dabeee4d0",
    "code": "multipleSelect",
    "categoryEntityType": "base$Incident",
    "configuration": {
      "_entityName": "sys$CategoryAttributeConfiguration",
      "id": "2541bcad-cd95-d42a-a2d7-a63dabeee4d0-Configuration",
      "dependsOnAttributes": []
    },
    "isCollection": true,
    "required": false,
    "targetScreens": "base$Incident.edit#customFields",
    "defaultEntity": {},
    "createTs": "2021-09-06 21:46:14.558",
    "enumeration": "Created,Read,Updated,Deleted",
    "lookup": false,
    "orderNo": 1,
    "dataType": "ENUMERATION",
    "version": 1,
    "createdBy": "admin",
    "localeDescriptions": "",
    "name": "multipleSelect",
    "width": "100%",
    "category": {
      "_entityName": "sys$Category",
      "id": "a5ba0c4c-cbb8-2bf9-616f-b69332d5efac"
    }

The REST call that is done with it’s JSON body:

{
  "title": "Incident created through API",
  "description": "Incident created through API",
  "+multipleSelect": [
      "Read", "Updated"
  ]
}

There is no error /logging on creation through the API and the response even lists the values correctly:

{
    "_entityName": "base$Incident",
    "id": "e75b5a44-b0ee-f885-8d37-d24865555872",
    "createTs": "2021-11-15 12:13:40.948",
    "priority": "Normal",
    "version": 1,
    "status": "New",
    "nr": 3,
    "description": "Incident created through API",
    "title": "Incident created through API",
    "createdBy": "testuser",
    "updateTs": "2021-11-15 12:13:40.948",
    "+multipleSelect": [
        "Read",
        "Updated"
    ],
    "__securityToken": "iVsQyDswNQ+LLs8XBASKUCEVgKMY1S+4EtUilendA9kf+4j+a7KM3eKkH7bQMhqUn6HSSwH3ds8Wy54y99ivypPuxeSJ/p0o6/zltTf9+VlYCZonm6fW6J4po7g8pt07"
}

However, looking at the ‘CategoryAttributeValue’ records using the entity inspector, we see 4 (!) entries with the duplicated values and a parent entry. When opening the editor screen the duplicated values already appear and clicking the editor then leads to the following error:

12:16:03.262 ERROR com.haulmont.cuba.web.log.AppLog        - Exception in com.haulmont.cuba.web.widgets.CubaButton: 
com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:157) ~[vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:115) ~[vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:431) [vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:396) [vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:260) [vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:82) [vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) [vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1580) [vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425) [vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329) [cuba-web-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215) [cuba-web-7.2.15.jar:7.2.15]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) [servlet-api.jar:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.38]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.38]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.38]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.38]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.38]
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108) [spring-web-5.2.16.RELEASE.jar:5.2.16.RELEASE]
	at com.haulmont.addon.saml.web.security.saml.SamlLoginHttpRequestFilter.doFilter(SamlLoginHttpRequestFilter.java:110) [saml-addon-web-0.5.2.jar:na]
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113) [spring-web-5.2.16.RELEASE.jar:5.2.16.RELEASE]
	at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74) [spring-web-5.2.16.RELEASE.jar:5.2.16.RELEASE]
	at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:93) [cuba-web-7.2.15.jar:7.2.15]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.38]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.38]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [catalina.jar:9.0.38]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [catalina.jar:9.0.38]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [catalina.jar:9.0.38]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [catalina.jar:9.0.38]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:9.0.38]
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690) [catalina.jar:9.0.38]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [catalina.jar:9.0.38]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.38]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) [tomcat-coyote.jar:9.0.38]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-coyote.jar:9.0.38]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-coyote.jar:9.0.38]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-coyote.jar:9.0.38]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.38]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_221]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_221]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.38]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_221]
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.GeneratedMethodAccessor558.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_221]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_221]
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:153) ~[vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	... 40 common frames omitted
Caused by: java.lang.IllegalStateException: Duplicate key Read
	at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133) ~[na:1.8.0_221]
	at java.util.HashMap.merge(HashMap.java:1254) ~[na:1.8.0_221]
	at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320) ~[na:1.8.0_221]
	at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169) ~[na:1.8.0_221]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) ~[na:1.8.0_221]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[na:1.8.0_221]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[na:1.8.0_221]
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_221]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_221]
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_221]
	at com.haulmont.cuba.gui.components.listeditor.ListEditorPopupWindow.initValues(ListEditorPopupWindow.java:153) ~[cuba-gui-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.gui.components.listeditor.ListEditorPopupWindow.init(ListEditorPopupWindow.java:133) ~[cuba-gui-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.gui.components.AbstractWindow.init(AbstractWindow.java:104) ~[cuba-gui-7.2.15.jar:7.2.15]
	at com.haulmont.bali.events.EventHub.publish(EventHub.java:170) ~[cuba-global-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.gui.screen.Screen.fireEvent(Screen.java:128) ~[cuba-gui-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.gui.screen.UiControllerUtils.fireEvent(UiControllerUtils.java:60) ~[cuba-gui-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.web.sys.WebScreens.createScreen(WebScreens.java:262) ~[cuba-web-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.web.sys.WebScreens.create(WebScreens.java:179) ~[cuba-web-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.gui.components.listeditor.ListEditorDelegateImpl.openEditor(ListEditorDelegateImpl.java:192) ~[cuba-gui-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.gui.components.listeditor.ListEditorDelegateImpl.lambda$init$0(ListEditorDelegateImpl.java:113) ~[cuba-gui-7.2.15.jar:7.2.15]
	at com.haulmont.bali.events.EventHub.publish(EventHub.java:170) ~[cuba-global-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.web.gui.components.WebAbstractComponent.publish(WebAbstractComponent.java:100) ~[cuba-web-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.web.gui.components.WebButton.buttonClicked(WebButton.java:70) ~[cuba-web-7.2.15.jar:7.2.15]
	at com.haulmont.cuba.web.widgets.CubaButton.fireClick(CubaButton.java:76) ~[cuba-web-widgets-7.2.15.jar:na]
	at com.vaadin.ui.Button$1.click(Button.java:57) ~[vaadin-server-8.9.2-27-cuba.jar:8.9.2-27-cuba]
	... 44 common frames omitted

Can you confirm this to be an issue or are we doing something wrong? Thanks for any help.

Regards,
-b

Hi Berend! This is also reproducing for us. Thank you for reporting the problem. We have created the ticket on GitHub

Hi @i.morenov,

Thank you for coming back on this. Hope this also gets fixed soon as there is no workaround other than to avoid these kind of fields but as our configuration already has this setup I don’t see how we can solve this.

Regards,
-b

Hi,

Any news on this? Is a fix planned soon?

Regards,
-b

Hi Berend,

We are going to release a CUBA 7.2 patch next week (or the week after), so we’ll try to fix this issue by that time.

Regards,
Konstantin

1 Like

Thanks for your comment - this is something we can work with - great!