Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

fix: Improve error message for SQLitePersister #417

Gupta Arpit27c104ead7a2
diff --git a/burr/core/application.py b/burr/core/application.py
index f9aa54a2..ec324544 100644
--- a/burr/core/application.py
+++ b/burr/core/application.py
@@ -2248,6 +2248,10 @@ class ApplicationBuilder(Generic[StateType]):
"""
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:
diff --git a/burr/core/persistence.py b/burr/core/persistence.py
index 22c26174..966c0c52 100644
--- a/burr/core/persistence.py
+++ b/burr/core/persistence.py
@@ -164,6 +164,7 @@ class SQLLitePersister(BaseStatePersister):
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."""
@@ -192,6 +193,11 @@ class SQLLitePersister(BaseStatePersister):
"""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 = (