No error raised if setParamsResult expects a param call by name

Which tool versions are you using?

SDK: v14.19.0
Platform: v25.06.5
Python: v3.10
Isolation mode: venv

Current Behavior

We try to use the name= in the parametrization as much as possible. However, if the SetParamsResult is used with the UI path like in the image below, no error is raised but Viktor says everything was successful (while in reality nothing happened).

Expected Behavior

I expect some kind of error that the provided UI path does not exist or used name=

Context (optional, but preferred)

Hi @Vincentvd ,

Thank you for sharing this. I believe (but good to check) that the SetParamsResult allows you to add any dictionary structure without error, even if it does not match your parametrization structure.

For the setting of your parameters to be successful, however, it should align with the name argument if you are using it. In all other cases, the Parametrization class variable path should be defined.

In general, I would overwrite my existing params, and return the entire params variable, e.g.:

def set_params_method(self, params, **kwargs):
    params.a = 1
    params.b = 2
    params.c = 3
    return vkt.SetParamsResult(params)

I hope this helps.

Indeed, SetParamsResult accepts any dictionary, even with unexpected keys. In my opinion, this is just a gotcha that you, as a coder, should handle yourself.

The benefit of this behavior is that you can theoretically use it as an API method to return a simple calculation result without needing to create a view or other result, as long as you use keys that are not part of the parametrization. This is a rather creative way of creating a compute microservice. But I like the flexibility :slight_smile:

Of course you could also do that with a dataview, en not show the actual dataview. But I think SetParams is a bit more flexible in that regard.

But why don’t you get an error if you made a mistake? In classes, I also can’t set a property if that property does not exists, you will get an error then.

I don’t completely agree, with regular Python classes you can assign attributes afterwards. Dynamically setting an attribute is mostly possible, unless attribute assignment is overruled OR the class is a Frozen Dataclass, and even then it is actually possible to set attributes dynamically with some hacky methods.

Also remember that the SetParamsResult doesn’t know what the parametrization is, so technically it can’t check the keys. Without knowing Viktors internals: I think it just performs an API call to the database, sends the dict as a serialized json and there it is resolved. You could argue if it should raise an error there, but as I said in my previous post: from my perspective I like the flexibility. Maybe an optional ‘strict’ flag in the SetParamsResult would be an option.

Anyway: I believe you should always write integration test for any controller method. Including this one. There you can check (recursively) if the params and the setparamsresult share the same keys, and that should catch your mistakes, also in future iterations.

Regards,
Wichard.

1 Like