Invalid summary item key (used before) error when reloading app

Which tool versions are you using?

SDK: v14.4.0
Platform: v23.09.2
Python: v3.11
Isolation mode: venv

Current Behavior

Consider the following code (parametrization and controller for a project entity):

class ProjectParametrization(Parametrization):
    """parametrization of project"""

    project_information = Page("Project information")
    project_information.project_number = TextField("Project number")
    project_information.project_name = TextField("Project name")

class ProjectController(ViktorController):
    """controller for project entity"""

    viktor_enforce_field_constraints = True
    parametrization = ProjectParametrization()

    label = "Project"
    summary = Summary(
        project_number=SummaryItem("Project number", str, "parametrization", "project_information.project_number"),
        project_name=SummaryItem("Project name", str, "parametrization", "project_information.project_name"),
    )

    children = ["Analysis"]
    show_children_as = "Table"

This code works fine until new lines of code are added. When reload gets triggered, it throws the following error.

If I “keyboard-interrupt” this, type in “viktor-cli clear” and then start again by “viktor-cli start”, the error message will dissappear and the app works fine until changes are made and I get the same error again.

I have tried changing the keys in Summary(), but that has the same effect. It works until changes are made and then it throws this error again.

I have this problem in development environment. I have not tried this in production, but I have heard from colleagues that they don’t have this problem in production.

Expected Behavior

I could use the abovementioned temporary fixes, but I eventually expect not to see the error message again.

Hi Sina,

I checked the code locally and i am not able to recreate the problem. The summary works fine using this implementation on my end. Seems that there is some old data/configuration in the way in your development workspace. Propbably running viktor-cli.exe clear will solve the problem.

Let me know if this fixes the problem.

greetings,

Maarten

Hi Maarten,

Thank you for looking into that!

I have tried viktor-cli clear and it solves the problem temporarily. When I then make changes in other parts of the code, it throws this error again. So I have to clear old data/config again and again.

My guess is that somehow, somewhere the SummaryItem objects stick in cache (somehow escaping the stateless boundaries!!!) and the app does not allow creating new SummaryItem objects with the same key.

Suggestion for future SDK versions:
I understand that recreating this could be tricky, because it takes some time to play with it until it throws the error, but it might be helpful to look into the workflow and structure of the code and how it handles SummaryItem objects. Especially in development mode.

Good luck!