App gets stuck if optionfield becomes invalid in dynamic array

Eventhough a dynamic array isn’t ment to contain loads of rows. Due to the lack of multi select list in Table we could have a Dynamic Array of 100+ rows.
If there is an OptoinField of which the stored data is invalid with the values the platform gets stuck or might even crash:

image

The amount of warnings go through the roof which prevent the site from operating.

To reproduce:
Create a set params button to fill a dynamic array with values stored. Change the option list so the data becomes invalid.
Wait for the site to get stuck.

Hi Johan,

thanks for bringing this up, we are diving into it!

Will let you know when we have a solution.

Hi Johan,

We have tried to reproduce the error, see the code below.

“Unfortunately” the app doesn’t break (even with 3000 items in the dynamic array. You do get indeed a lot of error messages but the editor remains working (getting less responsive off course). With 200 items it’s still very responsive.

Could you provide more information, or ideally a code snippet with which we can reproduce this? How many other parameters do you have in your dynamic array and parametrization?

import viktor as vkt
import random

def get_options(params, **kwargs):
        # Dynamically get options from the TextField
        return params.options.split(',') if params.options else []

class Parametrization(vkt.Parametrization):
    options = vkt.TextField("Options (comma-separated)", default="A,B,C,D,E")

    fill_button = vkt.SetParamsButton("Fill Array", method="fill_array")
    change_options_button = vkt.SetParamsButton("Change Options", method="change_options")
    
    items = vkt.DynamicArray("Items")
    items.value = vkt.OptionField("Value", options=get_options)
    
    
class Controller(vkt.Controller):
    label = "Error Reproduction App"
    parametrization = Parametrization

    def fill_array(self, params, **kwargs):
        # Generate rows with random values from current options
        current_options = get_options(params)
        new_items = [{"value": random.choice(current_options)} for _ in range(3000)]
        return vkt.SetParamsResult({"items": new_items})

    def change_options(self, params, **kwargs):
        # Change the options to make stored data potentially invalid
        new_options = "X,Y,Z"
        return vkt.SetParamsResult({"options": new_options})

Okay, maybe due to our parametrization being bigger and maybe as we use that input for new OptionLists also.

Maybe just a clear all wanings button instead :slight_smile: