Migrating to different parametrization fields

Hi devs,

I changed the way of selecting an item in the parametrization class. Instead of using one autocompletefield I am using three different fields. The question that I have is what would be the ideal way of implementing this so that I would have backwords compatibility. There are a few projects already made with the old version and I want to make it so that these projects don’t break.

The ideal solution would be to take the value that was put in the old version and build a function which would insert the right values that are needed in the new version. Is this possible?

Greetings Bob

Hi Bob,

Thanks for the question.
If I understand correctly you want projects, which are already filled in in your database currently, to keep working with that same input while you change the parametrization of your app?
As VIKTOR apps are constructed to work with “Stateless” code (see our docs for more information on that) it is difficult to paste input from one version of an app to the next.

Therefore my advise would be to simply remember for yourself what the current input is and manually enter that input in an adjusted form into the app once you’ve altered your parametrization.

Hi Daniël,

So there is no way to automate this with a script?

Hi Bob,

You should be able to write your own script for this that uses the API to update the database. That script can be executed from the Parent entity of your defined projects. (You could add an ActionButton, to trigger it from the parent entity). It might look roughly like this:

def check_project_uses_old_params(params: Munch) -> bool:

def convert_to_new_format(params: Munch) -> Munch:
    return new_params

class ProjectParent(ViktorController):

    def update_old_projects(self, params, entity_id, **kwargs):
        project_entities = API().get_entity(entity_id).children()
        for project_entity in project_entities:
            current_project_params = project_entity.last_saved_params
            if check_project_uses_old_params(current_project_params):
                  new_project_params = convert_to_new_format(current_project_params)
        return ViktorResult()

Do note that this creates a new revision, with a working ‘format’. All old revisions are still not backwards compatible.

Please test this thoroughly in your development environment before you run this in any of your production environments, as an incorrect implementation might accidentally mutate the wrong production data.

Note: @BobBroersen , @dsommers and Myself talked about this in a separate conversation some more and Bob managed to get the conversion done succesfully!