Home > Software design >  How can i achive atomicity just like django orm in fastapi with sqlalchmey orm
How can i achive atomicity just like django orm in fastapi with sqlalchmey orm

Time:12-15

How can i achive atomicity just like django orm in fastapi with sqlalchmey orm. What i am trying to do is making a cron script which will delete data from s3 bucket and DB a lot of data. If some how s3 operation fails and it creates inconsistency or either case s3 pass and DB fails. So I want to achive atomicity like we have in django "with atomic transactions".

What i am trying to do is making a cron script which will delete data from s3 bucket and DB a lot of data.

CodePudding user response:

One simple approach would be this way,

def function_name(...):
   try:
       ...
       db.commit()
   except:
       db.rollback()
   finally:
       db.close()
  • Related