Which tool versions are you using?
SDK: v14.21.0
Python: v3.11
Isolation mode: venv
Problem
I get a ParamNotFoundError when trying to have multiple defaults and an OutputField in a DynamicArray.
import viktor as vkt
def sum_x_y(params, **kwargs):
return [row.x + row.y for row in params.array]
class Parametrization(vkt.Parametrization):
array = vkt.DynamicArray("Array", default=[{"x": 2, "y": 3}, {"x": 1, "y": 4}])
array.x = vkt.NumberField("X")
array.y = vkt.NumberField("Y")
array.output = vkt.OutputField("X + Y", value=sum_x_y)
class Controller(vkt.Controller):
parametrization = Parametrization
returns a ParamNotFoundError.
Workarounds
2 solutions exist:
-
remove
default=[{"x": 2, "y": 3}, {"x": 1, "y": 4}]
and instead set default values directly to x and y:array.x = vkt.NumberField("X", default=2) array.y = vkt.NumberField("Y", default=3)
But then only a single default value can be assigned per variable.
-
move the OutputField to outside of the DynamicArray:
def total_sum(params, **kwargs): rows = [row.x + row.y for row in params.array2] return sum(rows) class Parametrization(vkt.Parametrization): array = vkt.DynamicArray("Array", default=[{"x": 2, "y": 3}, {"x": 1, "y": 4}]) array.x = vkt.NumberField("X") array.y = vkt.NumberField("Y") output = vkt.OutputField("Total", value=total_sum)
But then we cannot output values per row.
Conclusion
Is this a bug or un purpose? Would you know perhaps of other workarounds?