UserMessage not appearing in the app

Which tool versions are you using?

SDK: v14.21.0
Platform: v25.06.4
Python: v3.11
Isolation mode: venv

Current Behavior

I’m trying to show the user a warning, which shouldn’t forbid continuing the following steps.
Violations work as intended, but UserMessage.warning (/.info/.success) aren’t working. The message only appears in the terminal (when in dev mode), and not at all in the publication state.

Here’s a shortened version of what I’m attempting to do:

import viktor as vkt


def check_step1(params, **kwargs):
    """Warn if the toggle is On"""
    violations = []
    if params.step1.bool:
        msg = "Toggle shouldn't be On"

        # Record the violation
        if True:  # no impact on the user messages
            violation = vkt.InputViolation(msg, fields=["step1.bool"])
            print(msg)
            violations.append(violation)

        # User messages - NOT WORKING
        vkt.UserMessage.info(f"INFO: {msg}")
        vkt.UserMessage.warning(f"WARNING: {msg}")
        vkt.UserMessage.success(f"SUCCESS: {msg}")

    # Show the violations
    if violations:
        msgs = ". ".join([f"{v.message}. Fields: {v.fields}" for v in violations])
        raise vkt.UserError(f"ERROR! {msgs}", input_violations=violations)


class Parametrization(vkt.Parametrization):
    step1 = vkt.Step("Step1", on_next=check_step1)
    step1.bool = vkt.BooleanField("Toggle", default=False)

    step2 = vkt.Step("Step2")
    step2.txt = vkt.Text("Welcome to step 2")


class Controller(vkt.Controller):
    parametrization = Parametrization

Context

I want to use user messages because I have a case where a value x should be smaller than x_warn, and must be smaller than x_max (both bounds depend on multiple parameters and are calculated on_next). I therefore want to warn the user if they input x > x_warn, and forbid them from inputting x > x_max.

User messages are retrieved on a polling interval. My hypothesis is that the check_step1 method returns before that time. I think you are right to expect to see the message, so this is something we need to look into. Thanks for reporting.

1 Like

Thanks for your message Raoul.

Am I perhaps misunderstanding how user messages should be used? Should they be used at another stage than on next?

Hi Remi,

No you are not misunderstanding how they should be used. I’ll try to explain what the current behavior is; lets say the user messages are polled by the FE with a 1 second interval. If your on_next method returns within that second the message won’t be visible in the UI. I understand that this behavior is unexpected, so I think it is something that should be addressed on our side.