diff --git a/burr/core/application.py b/burr/core/application.py index 06cc9f41..b59d7915 100644 --- a/burr/core/application.py +++ b/burr/core/application.py @@ -2207,10 +2207,14 @@ def with_state_persister( """ if on_every != "step": raise ValueError(f"on_every {on_every} not supported") - if hasattr(persister, 'initialize') and not persister.is_initialized(): - raise RuntimeError( - "Uninitialized persister. Make sure to call .initialize() before passing it to the ApplicationBuilder." - ) + + # Check if 'is_initialized' exists and whether it returns False, indicating the persister is uninitialized + if hasattr(persister, 'is_initialized'): + if not persister.is_initialized(): + raise RuntimeError( + "RuntimeError: Uninitialized persister. Make sure to call .initialize() before passing it to the ApplicationBuilder" + ) + # If the persister is valid and initialized, add it to lifecycle adapters if not isinstance(persister, persistence.BaseStateSaver): self.lifecycle_adapters.append(persister) else: diff --git a/burr/core/persistence.py b/burr/core/persistence.py index 966c0c52..bb51da5d 100644 --- a/burr/core/persistence.py +++ b/burr/core/persistence.py @@ -88,7 +88,11 @@ class BaseStatePersister(BaseStateLoader, BaseStateSaver, metaclass=ABCMeta): Extend this class if you want an easy way to implement custom state storage. """ - pass + def is_initialized(self) -> bool: + """Check if the persister has been initialized. Default behavior is False. + Persisters that require initialization can override this method. + """ + return False class PersisterHook(PostRunStepHook):