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

fix image migration for duplicate captions #5549

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions dojo/db_migrations/0118_remove_finding_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from django.db import migrations, models, IntegrityError, transaction
import uuid
import django.db.models.deletion
import logging

logger = logging.getLogger(__name__)


def move_images_to_files(apps, schema_editor):
Expand All @@ -20,10 +23,21 @@ def move_images_to_files(apps, schema_editor):
file=image.image
)
except IntegrityError:
passed = True
pass
logger.info('retrying migrate migration for image %s with caption %s by uuid', image.image.name, image.caption)
try:
with transaction.atomic():
file = FileUpload_model.objects.create(
title=image.caption[:50] + '-' + caption_uuid,
file=image.image
)
except IntegrityError:
passed = True
pass

if not passed:
finding.files.add(file)
else:
logger.warn('unable to migrate image %s with caption %s', image.image.name, image.caption)


class Migration(migrations.Migration):
Expand Down