diff --git a/ops/main.py b/ops/main.py index dca8da056..c38727168 100755 --- a/ops/main.py +++ b/ops/main.py @@ -176,7 +176,7 @@ def __init__(self, charm_dir: Path): self._charm_dir = charm_dir self._exec_path = Path(sys.argv[0]) - if 'JUJU_DISPATCH_PATH' in os.environ: + if 'JUJU_DISPATCH_PATH' in os.environ and (charm_dir / 'dispatch').exists(): self._init_dispatch() else: self._init_legacy() diff --git a/test/test_main.py b/test/test_main.py index 99fe66b7b..7829c80ce 100755 --- a/test/test_main.py +++ b/test/test_main.py @@ -602,6 +602,12 @@ def test_setup_action_links(self): self.assertTrue(action_hook.exists()) +class TestMainWithNoDispatchButJujuIsDispatchAware(TestMainWithNoDispatch): + def _call_event(self, rel_path, env): + env["JUJU_DISPATCH_PATH"] = str(rel_path) + super()._call_event(rel_path, env) + + class TestMainWithNoDispatchButScriptsAreCopies(TestMainWithNoDispatch): hooks_are_symlinks = False