Skip to content

Commit

Permalink
fix: Improve error message for SQLitePersister #417
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitgupta-it committed Nov 8, 2024
1 parent 6d3d7e9 commit 5e31502
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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():
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:
"""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

0 comments on commit 5e31502

Please sign in to comment.