From 3dc51d4217e2c84a93ac02a8da2a674859b8dd8d Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Sat, 4 Dec 2021 13:30:59 +0100 Subject: [PATCH] fix image migation for duplicate captions --- .../0118_remove_finding_images.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dojo/db_migrations/0118_remove_finding_images.py b/dojo/db_migrations/0118_remove_finding_images.py index 0946b6b3abb..bffc069abda 100644 --- a/dojo/db_migrations/0118_remove_finding_images.py +++ b/dojo/db_migrations/0118_remove_finding_images.py @@ -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): @@ -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):