Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve error message for SQLitePersister #417 #418

Merged
4 changes: 4 additions & 0 deletions burr/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,10 @@ 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():
arpitgupta-it marked this conversation as resolved.
Show resolved Hide resolved
raise RuntimeError(
"Uninitialized persister. Make sure to call .initialize() before passing it to the ApplicationBuilder."
)
if not isinstance(persister, persistence.BaseStateSaver):
self.lifecycle_adapters.append(persister)
else:
Expand Down
6 changes: 6 additions & 0 deletions burr/core/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def __init__(
db_path, **connect_kwargs if connect_kwargs is not None else {}
)
self.serde_kwargs = serde_kwargs or {}
self._initialized = False

def create_table_if_not_exists(self, table_name: str):
"""Helper function to create the table where things are stored if it doesn't exist."""
Expand Down Expand Up @@ -192,6 +193,11 @@ def initialize(self):
"""Creates the table if it doesn't exist"""
# Usage
self.create_table_if_not_exists(self.table_name)
self._initialized = True

def is_initialized(self) -> bool:
skrawcz marked this conversation as resolved.
Show resolved Hide resolved
"""Check if the persister is initialized."""
return self._initialized

def list_app_ids(self, partition_key: Optional[str], **kwargs) -> list[str]:
partition_key = (
Expand Down