B
B
beduin012018-05-07 16:04:46
Python
beduin01, 2018-05-07 16:04:46

How to make rollback transactions?

Suppose my request did not work, how to make rollback ? tr goes in my cycle.

tr_list = []
try:
  for tr in ready_query.all():
    tr_list.append(tr.asdict(follow=follow_list, exclude=exclude_columns))
except SQLAlchemyError as e:
  # как сделать rollback ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
techkuz, 2018-05-08
@techkuz

rollback is needed if you have data changes in the database at the time of the fall. In your code, in the for loop, elements are inserted into the sheet (without connection to the database). If an SQLalchemy exception is thrown, then at the time of the execution of all (), when receiving the elements. But then there will be nothing to do rollback, because. you yourself do not make any changes (in other words, set operations), only get.
If you want rollback to return at least some of the elements from the all() request, then it will not work, because this get is executed once and all elements are returned at once, so it will either succeed or fail with an exception (in the case of the latter, there will be nowhere to rollback (=rollback) again)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question