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

Let Resource rollback if import throws exception #377

Merged
merged 3 commits into from Jan 15, 2016
Merged

Let Resource rollback if import throws exception #377

merged 3 commits into from Jan 15, 2016

Conversation

jarekwg
Copy link
Contributor

@jarekwg jarekwg commented Dec 30, 2015

If a db exception (such as Key (name, primary_contact)=(squaberblabeergabatersh, Jenny Susans) already exists. is thrown during Resource.import_data (when we try to save the instance), then attempting to rollback the database may result in
TransactionManagementError “You can't execute queries until the end of the 'atomic' block”, causing import_data to throw an unhelpful transaction exception. With this fix the function will exit cleanly and the db error will be returned in one of the row_results as intended.

No time to add a failing test at the moment, but hopefully this is sufficient information to go on..

@bmihelac
Copy link
Member

Thanks for contributing @jarekwg

Is it possible to add a test case for this change?

Also includes:
-Some pep8 cleanup
-Testing against python3.5
-No longer testing against django1.5
@jarekwg
Copy link
Contributor Author

jarekwg commented Jan 11, 2016

Hi, no worries.
I rebased the branch and added a failing test.
I've also made an .isort.cfg file that I can push up if you like. (Useful for automating import cleaning)

bmihelac added a commit that referenced this pull request Jan 15, 2016
Let Resource rollback if import throws exception
@bmihelac bmihelac merged commit 3ff406f into django-import-export:master Jan 15, 2016
@bmihelac
Copy link
Member

Thanks!

@bmihelac
Copy link
Member

I've also made an .isort.cfg file that I can push up if you like. (Useful for automating import cleaning)

yes please, add another PR. I did not work with https://github.com/timothycrosley/isort yet, but it looks nice.

bmihelac added a commit that referenced this pull request Mar 8, 2016
…nagementError #399

wrap save_m2m in transaction.atomic()

references #377
@jarekwg jarekwg deleted the bugfix/rollback-after-db-exception branch May 8, 2020 11:49
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

Successfully merging this pull request may close these issues.

None yet

2 participants