set_state not setting the state immediately

Konstantinos Tsakalozos kos.tsakalozos at canonical.com
Tue Oct 3 12:34:28 UTC 2017


Hi,

It seems the reactive framework is flushing the states at the end of hook
execution. This may surprise charm authors. Consider the following code:

@when_not("initialized")
def init():
    must_be_called_exactly_once()
    set_state("initialized")

@when("initialized")
@when_not("ready")
def get_ready():
    this_call_fails()
    set_state("ready")

As a charm author I would expect the "initialized" state set right after
the must_be_called_exactly_once() is called. However, the framework is not
persisting the "initialized" state at that point, and it moves on to
trigger the get_ready(). Since this_call_fails() happens on
the  get_ready() method I would expect the "initialized" state to be set
when the failure is resolved.

The reason why the states are not set right away is that the entire hook is
tried after resolving the error. However, since hooks are hidden from the
charm author it is not clear when a hook starts and when it finishes. Also,
the set_state's behaviour of not immediately setting the state is
counter-intuitive.

Thanks,
Konstantinos Tsakalozos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20171003/3be1944d/attachment.html>


More information about the Juju mailing list