How can i achive atomicity just like django orm in fastapi with sqlalchmey orm

Question:

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.

Asked By: gautam thakur

||

Answers:

One simple approach would be this way,

def function_name(...):
   try:
       ...
       db.commit()
   except:
       db.rollback()
   finally:
       db.close()
Answered By: ilyasbbu
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.