On 4 October 2017 at 00:51, Mike Wilson <mike.wil...@canonical.com> wrote: > So the best practice here is to touch a file and test for the existence of > that file before running must_be_called_exactly_once()? > > I think part of the issue here is that without knowing the extent of the > hook it is hard to enforce idempotency as a charm writer. It's easy to look > at the code above and say that is it idempotent since the init function is > wrapped in a when_not and the initialized state is set at the bottom of > init.
Individual handlers should be idempotent, so it doesn't matter about the extent of the hook, or even if the chained handlers being triggers are running in the same hook. Assume your handlers get called multiple times, because they may be. Yes, it looks idempotent but it isn't. An assumption is being made that the state changes get committed immediately, but these changes are actually transactional and following the same transactional behaviour as the Juju hook environment [1]. I think this can certainly be explained better in the docs, but I can't think of a way to stop this being an easy error to make. [1] spot the DBA -- Stuart Bishop <stuart.bis...@canonical.com> -- Juju mailing list Juju@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju