Skip to content

Fix stream field ids

hypha.apply.review.management.commands.fix_stream_field_ids

Command

Bases: BaseCommand

help class-attribute instance-attribute

help = 'Fix stream fields so all have unique IDs.'

handle

handle(*args, **options)
Source code in hypha/apply/review/management/commands/fix_stream_field_ids.py
@transaction.atomic
def handle(self, *args, **options):
    with connection.cursor() as cursor:
        cursor.execute("SELECT id, form_fields FROM review_reviewform")
        form_fields = cursor.fetchall()

    for row in form_fields:
        review_id, review_form = row
        form = json.loads(review_form)
        updated = False
        for field in form:
            if field["id"] == "976386e1-3a66-490f-9e82-bfbe1f134cf2":
                field["id"] = str(uuid.uuid4())
                updated = True

        if updated:
            updated_form = json.dumps(form)
            with connection.cursor() as cursor:
                cursor.execute(
                    "UPDATE review_reviewform SET form_fields = %s WHERE id = %s",
                    [updated_form, review_id],
                )