Adding workspace_id to set_params

Since the new SDK update 14.9.0 API method set_params requires workspace ID:

  File "controller", in import_entity_and_children
    current_entity.set_params(params=last_saved_params)
  File "viktor\api_v1.pyx", line 589, in viktor.api_v1.Entity.set_params
  File "viktor\api_v1.pyx", line 1294, in viktor.api_v1._API.set_entity_params
ValueError: `workspace_id` is required if API is initiated outside of a VIKTOR app.

The problem is that workspace_id cannot be passed to set_params, however it is needed in this method as it uses set_entity_params, which does need workspace_id.

How can this be fixed?

Hi Peter,

This might be a bug on our end, depending on how you’ve set it up (it should autoselect the correct workspace id if run from within a app/workspace). Could you provide a bit more context on how you are using the API?

For example, are you using it within an app (seems likely, since your snippet mentions a controller)? e.g.


api = API()
current_entity = api.get_entity(entity_id)
current_entity.set_params(params)

or are you trying to do this from an external script?

api = API(token=x, environment=y)
current_entity = api.get_entity(entity_id)
current_entity.set_params(params)

Also, could you tell me which Connector Version you are running? You can spot this when you run your app:

2024-05-03 10:52:20.312 INFO    :  __      __ __  __  __        
2024-05-03 10:52:20.312 INFO    :  \ \    / / | | | |/ /      
2024-05-03 10:52:20.312 INFO    :   \ \  / /  | | | ' /       
2024-05-03 10:52:20.312 INFO    :    \ \/ /   | | |  <        
2024-05-03 10:52:20.312 INFO    :     \  /    | | | . \       
2024-05-03 10:52:20.312 INFO    :      \/     |_| |_|\_\     
2024-05-03 10:52:20.312 INFO    :   _______   ____    _____     
2024-05-03 10:52:20.312 INFO    :  |__   __| / __ \  |  __ \  
2024-05-03 10:52:20.312 INFO    :     | |   | |  | | | |__) |   
2024-05-03 10:52:20.312 INFO    :     | |   | |  | | |  _  /    
2024-05-03 10:52:20.312 INFO    :     | |   | |__| | | | \ \  
2024-05-03 10:52:20.312 INFO    :     |_|    \____/  |_|  \_\
2024-05-03 10:52:20.313 INFO    : VIKTOR connector v5.24.2
 __________________________________________________^^^^^^^

Hi Kevin,

I was using viktor connector v5.22.2 in development. As far as I know I am not using it outside of an app, however I am trying to import params and pass them to a child entity of the entity that throws the error. Before we just had:

        entity_id = kwargs.get("entity_id")

        current_entity = API().get_entity(entity_id)

Which used to work fine. Since the update it says it needs a workspace_id.

Hi Peter,

I think that the problem lies in the older connector. The autoselection of the workspace_id was introduced in v5.24.0 (released on 14/03/2024). Could you reinstall your app?

viktor-cli install

This should install the latest connector for you (which is v5.24.2), which should fix your problem.

Please let me know if this solves your problem.

@peter_vw Your error looks similar to the one I experienced. It turned out I wasn’t using the latest patch version of Python. I was stil on 3.10.8, while 3.10.11 was the latest 3.10 version.

Despite what @kvangiessen proposed in that topic, we later encountered exactly the same issue on a colleagues computer. That was also fix by upgrading 3.10.8 to 3.10.11.

But come to think of it: Maybe the viktor-cli install be both executed after installing the new Python patch version was the actual fix :thinking:

Hi,
Thank you for your help! Updating the viktor connecter fixed the problem! I was using python 3.11 the whole time, so that was not the mistake I encountered. For me viktor-cli install was enough.

2 Likes