From d49fa98500888e2058c277867125d8f5f261ec35 Mon Sep 17 00:00:00 2001 From: PietroPasotti Date: Tue, 30 Jan 2024 22:37:48 +0100 Subject: [PATCH] fix(charm): make collect-status a LifeCycleEvent to avoid logging it (#1080) --- ops/charm.py | 3 ++- ops/framework.py | 1 + test/test_main.py | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ops/charm.py b/ops/charm.py index 317e9bf0e..164dd378a 100644 --- a/ops/charm.py +++ b/ops/charm.py @@ -41,6 +41,7 @@ EventSource, Framework, Handle, + LifecycleEvent, Object, ObjectEvents, ) @@ -914,7 +915,7 @@ def defer(self) -> NoReturn: 'this event until you create a new revision.') -class CollectStatusEvent(EventBase): +class CollectStatusEvent(LifecycleEvent): """Event triggered at the end of every hook to collect statuses for evaluation. If the charm wants to provide application or unit status in a consistent diff --git a/ops/framework.py b/ops/framework.py index aa46884c7..fcd250ab9 100644 --- a/ops/framework.py +++ b/ops/framework.py @@ -923,6 +923,7 @@ def _reemit(self, single_event_path: Optional[str] = None): elif self._event_name and self._event_name != event.handle.kind: # if the event we are emitting now is not the event being # dispatched, and it also is not an event we have deferred, + # and is also not a lifecycle (framework-emitted) event, # it must be a custom event logger.debug("Emitting custom event %s.", event) diff --git a/test/test_main.py b/test/test_main.py index 7cfa51ce1..7c1849565 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -866,9 +866,11 @@ def _call_event(self, rel_path: Path, env: typing.Dict[str, str]): def test_setup_event_links(self): """Test auto-creation of symlinks caused by initial events.""" - all_event_hooks = [f"hooks/{name.replace('_', '-')}" - for name, event_source in self.charm_module.Charm.on.events().items() - if issubclass(event_source.event_type, ops.LifecycleEvent)] + all_event_hooks = [ + f"hooks/{name.replace('_', '-')}" + for name, event_source in self.charm_module.Charm.on.events().items() + if issubclass(event_source.event_type, (ops.CommitEvent, ops.PreCommitEvent)) + ] initial_events = { EventSpec(ops.InstallEvent, 'install'),