Flask-Excel icon indicating copy to clipboard operation
Flask-Excel copied to clipboard

auto_commit=False in save_to_database and save_book_to_database to allow rollback

Open crbertoldo opened this issue 5 years ago • 3 comments

Hello,

I suggest telling about the auto_commit parameter in the documentation for save_to_database and save_book_to_database methods. In my need, when uploading a big table, if any row goes wrong (e.g.: foreign key constraint fails) I'd like to roll back the whole process. With auto_commit=False (default, omitted) I cannot, but when passing it as True and then committing the db.session, if any row goes wrong, an exception can be raised and then I perform the rollback, like below:

try:
    request.save_to_database(
        field_name='file',
        session=db.session,
        table=model,
        initializer=init_func,
        auto_commit=False)
    db.session.commit()
except:
    db.session.rollback()

crbertoldo avatar Jan 14 '20 22:01 crbertoldo

Are you suggesting a documentation update? What you are doing is agreeable and this library did not prevent you from doing it.

chfw avatar Jan 15 '20 05:01 chfw

@chfw, yes, a documentation update, please. And also to inform here who needs this.

crbertoldo avatar Jan 15 '20 17:01 crbertoldo

Sure! Thanks for using this library. I will get it update over the weekend.

chfw avatar Jan 15 '20 19:01 chfw