Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Sets initialized values on persisters where it makes sense
Stefan Krawczyk988b9fbff259
diff --git a/burr/core/persistence.py b/burr/core/persistence.pyindex ae0d55e5..36c8a23c 100644--- a/burr/core/persistence.py+++ b/burr/core/persistence.py@@ -198,14 +198,18 @@ class SQLLitePersister(BaseStatePersister):self._initialized = Truedef 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 Truecursor = 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._initializeddef 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.pyindex 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 = Truedef 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 Truecursor = 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._initializeddef list_app_ids(self, partition_key: str, **kwargs) -> list[str]:"""Lists the app_ids for a given partition_key."""