0

i am trying to save 2 record in to database, in try block i have saved those two records :

session.add(rec_1)
await session.commit()
await session.refresh(rec_1)

i need rec_1 id, so i have saved and accessed in rec_2

session.add(rec_2)
await session.commit()
await session.refresh(rec_2)

in except block i have used session.rollback():

if any error occurs after saving the rec_1, from the database rec_1 is not roll backing ,

if any error occurs i don't want to save the any of the records.

please guide me how to handle this situation,

kumar
  • 1
  • 1
  • What kind of database are you using? Are you using explicit transactions and have you disabled autocommit? Did you start a transaction first? – MatsLindh Apr 14 '23 at 08:14

0 Answers0