Altinn / altinn-studio

Next generation open source Altinn platform and applications.
https://docs.altinn.studio
BSD 3-Clause "New" or "Revised" License
115 stars 70 forks source link

Duplicate key exception when using options file multiple times #5693

Closed torbjokv closed 3 years ago

torbjokv commented 3 years ago

Describe the bug

If you use the same option file multiple times, you get an exception after posting the form.

To Reproduce

Steps to reproduce the behavior:

  1. Create an options file like App\options\JaNei.json
  2. Use it two or more times in the same layout
  3. Send and wait for receipt

or use this unit test:

https://github.com/torbjokv/altinn-studio/blob/bug/options-duplicate-key/src/Altinn.Apps/AppTemplates/AspNet/Altinn.App.PlatformServices.Tests/Implementation/AppBaseTests.cs

Expected behavior

Expect to be allowed to re-use one options file multiple times

Screenshots

If applicable, add screenshots or animated gif to help explain your problem.

Stack trace:

fail: Altinn.App.Api.Controllers.ProcessController[0]
      Process next failed.: System.ArgumentException: An item with the same key has already been added. Key: JaNei
         at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
         at Altinn.App.Services.Implementation.AppBase.GetOptionsDictionary(String formLayout)
         at Altinn.App.Services.Implementation.AppBase.GenerateAndStoreReceiptPDF(Instance instance, String taskId, DataElement dataElement, Type dataElementModelType)
         at Altinn.App.Services.Implementation.AppBase.OnEndProcessTask(String taskId, Instance instance)
         at Altinn.App.Api.Controllers.ProcessController.NotifyAppAboutEvents(IAltinnApp altinnApp, Instance instance, List`1 events) 
         at Altinn.App.Api.Controllers.ProcessController.UpdateProcessAndDispatchEvents(Instance instance, ProcessStateChange processStateChange)
         at Altinn.App.Api.Controllers.ProcessController.NextElement(String org, String app, Int32 instanceOwnerPartyId, Guid instanceGuid, String elementId)

JaNei.json:

[
    {
        "value": true,
        "label": "Ja"
    },
    {
        "value": false,
        "label": "Nei"
    }
]

layout:

{
    "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json",
    "data": {
      "layout": [
        {
            "id": "internett",
            "type": "RadioButtons",
            "textResourceBindings": {
              "title": "InternettLedetekst"
            },
            "dataModelBindings": {
              "simpleBinding": "Innhold.Internett"
            },
            "required": true,
            "optionsId": "JaNei"
          },
          {
            "id": "tv",
            "type": "RadioButtons",
            "textResourceBindings": {
              "title": "TvLedetekst"
            },
            "dataModelBindings": {
              "simpleBinding": "Innhold.Tv"
            },
            "required": true,
            "optionsId": "JaNei"
          },
        {
          "id": "send-inn",
          "type": "Button",
          "textResourceBindings": {
            "title": "Send inn"
          },
          "dataModelBindings": {}
        }
      ]
    }
  }

Additional info

Add any other relevant context info about the problem here. For example OS (Windows, MacOS, iOS), browser (Chrome, Firefox, Safari), device (iPhone, laptop), screen-size, etc.

acn-sbuad commented 3 years ago

Nugets 3.2.3-alpha are ready for test

acn-sbuad commented 3 years ago

Following up with @torbjokv for test.

torbjokv commented 3 years ago

Tested and verified fix 👍