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.

Sets initialized values on persisters where it makes sense

Stefan Krawczyk988b9fbff259
diff --git a/burr/core/persistence.py b/burr/core/persistence.py
index ae0d55e5..36c8a23c 100644
--- a/burr/core/persistence.py
+++ b/burr/core/persistence.py
@@ -198,14 +198,18 @@ class SQLLitePersister(BaseStatePersister):
self._initialized = True
def is_initialized(self) -> bool:
- """Check if persister is properly initialized."""
+ """This checks to see if the table has been created in the database or not.
+ It defaults to using the initialized field, else queries the database to see if the table exists.
+ It then sets the initialized field to True if the table exists.
+ """
if self._initialized:
return True
cursor = self.connection.cursor()
cursor.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name=?", (self.table_name,)
)
- return cursor.fetchone() is not None
+ self._initialized = cursor.fetchone() is not None
+ return self._initialized
def list_app_ids(self, partition_key: Optional[str], **kwargs) -> list[str]:
partition_key = (
diff --git a/burr/integrations/persisters/postgresql.py b/burr/integrations/persisters/postgresql.py
index 38137524..c5d152c2 100644
--- a/burr/integrations/persisters/postgresql.py
+++ b/burr/integrations/persisters/postgresql.py
@@ -119,7 +119,10 @@ class PostgreSQLPersister(persistence.BaseStatePersister):
self._initialized = True
def is_initialized(self) -> bool:
- """Returns .initialized() has been called"""
+ """This checks to see if the table has been created in the database or not.
+ It defaults to using the initialized field, else queries the database to see if the table exists.
+ It then sets the initialized field to True if the table exists.
+ """
if self._initialized:
return True
cursor = self.connection.cursor()
@@ -127,7 +130,8 @@ class PostgreSQLPersister(persistence.BaseStatePersister):
"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = %s)",
(self.table_name,),
)
- return cursor.fetchone()[0]
+ self._initialized = cursor.fetchone()[0]
+ return self._initialized
def list_app_ids(self, partition_key: str, **kwargs) -> list[str]:
"""Lists the app_ids for a given partition_key."""