-
Notifications
You must be signed in to change notification settings - Fork 80
Rework migration 19 #1074
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
Rework migration 19 #1074
Conversation
|
Minimal changes based on #1073 |
| sid = transaction.savepoint() # Start a savepoint | ||
| try: | ||
| Artifact.objects.bulk_create(artifact_batch.values(), batch_size=BATCH_SIZE) | ||
| except IntegrityError: | ||
| transaction.savepoint_rollback(sid) # Only rollback this batch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should solve TransactionManagementError
| sid = transaction.savepoint() # Start a savepoint | ||
| try: | ||
| Artifact.objects.bulk_create(artifact_batch.values(), batch_size=BATCH_SIZE) | ||
| except IntegrityError: | ||
| transaction.savepoint_rollback(sid) # Only rollback this batch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sid = transaction.savepoint() # Start a savepoint | |
| try: | |
| Artifact.objects.bulk_create(artifact_batch.values(), batch_size=BATCH_SIZE) | |
| except IntegrityError: | |
| transaction.savepoint_rollback(sid) # Only rollback this batch | |
| try: | |
| with transaction.atomic(): | |
| Artifact.objects.bulk_create(artifact_batch.values(), batch_size=BATCH_SIZE) | |
| except IntegrityError: |
An atomic block should handle all this, a nested transaction is just savepoints behind the scenes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.