-
-
Notifications
You must be signed in to change notification settings - Fork 782
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
savepoint_rollback() after an IntegrityError gives TransactionManagementError #399
Comments
+1, running into the same issue at the moment |
reference: #377 |
This should be fixed in branch 412-drop-django-15-support https://github.com/django-import-export/django-import-export/tree/412-drop-django-15-support Can you please test if this works for your case? |
I'm getting this on My case is having a "legal person" model that have O2O field to a Person model and a code field that is preferred for determining the right legal person. I'm trying to determine a Person by multiple fields with my custom widget and today there was two legal person rows with different codes. So it failed since I'm returning a second legal person connected to the same Person. But it doesn't raise the IntegrityError exception in my widget code for some reason. Will continue investigating it tomorrow. |
AFAIU the reason is that Resource.import_row doesn't account for IntegrityError possibility and this example from Django docs cannot be used:
So we need to prevent any |
…possible rollbacks
Add `atomic_if_using_transaction` context manager and use it instead of if/else statements. Wrap `before_import`, `import_row`, `after_import` calls into `atomic_if_using_transaction`. Add tests. Refs: django-import-export#609, django-import-export#399, django-import-export#610
Add `atomic_if_using_transaction` context manager and use it instead of if/else statements. Wrap `before_import`, `import_row`, `after_import` calls into `atomic_if_using_transaction`. Add tests. Refs: django-import-export#609, django-import-export#399, django-import-export#610
@bmihelac In dd1c085 you removed the exception handling from the call to Did you mean to remove the Because what happens now is that if you call I will prepare an MR to add
to the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey,
I noticed that if my model throws an
IntegrityError
while saving, and we do asavepoint_rollback()
after that, it throwsTransactionManagementError
.I investigated a little and found that in an
atomic()
block, Integrity Error causes automatic rollbacks, so callingsavepoint_rollback()
raises error.The text was updated successfully, but these errors were encountered: