Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto_commit=False in save_to_database and save_book_to_database to allow rollback #47

Open
crbertoldo opened this issue Jan 14, 2020 · 3 comments

Comments

@crbertoldo
Copy link

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 crbertoldo changed the title auto_commit in save_to_database and save_book_to_database to allow rollback auto_commit=False in save_to_database and save_book_to_database to allow rollback Jan 14, 2020
@chfw
Copy link
Member

chfw commented Jan 15, 2020

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

@crbertoldo
Copy link
Author

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

@chfw
Copy link
Member

chfw commented Jan 15, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants