Make sure to do a rollback in case of errors in wrap_finish() #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While integrating the query wrapper into one of our loading scripts, I noticed as I was testing the outcome that even if a
wrapper:query(...)call failed, and aborted the script, previous database updates within the same script would still be committed.This happens because
wrap_query, in case of an error and whereself.on_error == 'abort', callsself:finish(), which in the default implementation proceeds to just write the log entries and do aself:commit().As this was somewhat surprising to me, I felt that perhaps
wrap_finishshould do a rollback before writing the log entries if there were any errors.If one doesn't want a rollback to happen in case of errors, it's easy enough to set
self.on_errorto something else than abort, and handle errors manually.Alternatively, one can also do some checkpointing by just calling
wrapper:commit()at well-chosen places throughout a script, if there are partial changes that should be preserved.