Skip to content

Commit

Permalink
Merge pull request #996 from Wannabeasmartguy/main
Browse files Browse the repository at this point in the history
Fix a bug SqlAssistantStorage can't save data
  • Loading branch information
ashpreetbedi authored Jun 1, 2024
2 parents 22cb72f + 21b4003 commit e1dd00a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions phi/storage/assistant/sqllite.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,21 @@ def upsert(self, row: AssistantRun) -> Optional[AssistantRun]:

try:
sess.execute(stmt)
except OperationalError:
# Create table if it does not exist
self.create()
sess.execute(stmt)
return self.read(run_id=row.run_id)
sess.commit() # Make sure to commit the changes to the database
return self.read(run_id=row.run_id)
except OperationalError as oe:
logger.error(f"OperationalError occurred: {oe}")
self.create() # This will only create the table if it doesn't exist
try:
sess.execute(stmt)
sess.commit()
return self.read(run_id=row.run_id)
except Exception as e:
logger.error(f"Error during upsert: {e}")
sess.rollback() # Rollback the session in case of any error
except Exception as e:
logger.error(f"Error during upsert: {e}")
sess.rollback()

def delete(self) -> None:
if self.table_exists():
Expand Down

0 comments on commit e1dd00a

Please sign in to comment.