From d341afc8796a8476a441d4b70ad7b45933067c6f Mon Sep 17 00:00:00 2001 From: amickan Date: Thu, 19 Dec 2024 12:43:34 +0100 Subject: [PATCH] Fix migration --- .../0065_create_interfaces_for_jobs.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/grandchallenge/algorithms/migrations/0065_create_interfaces_for_jobs.py b/app/grandchallenge/algorithms/migrations/0065_create_interfaces_for_jobs.py index 8cd37d5f3..8444d0b79 100644 --- a/app/grandchallenge/algorithms/migrations/0065_create_interfaces_for_jobs.py +++ b/app/grandchallenge/algorithms/migrations/0065_create_interfaces_for_jobs.py @@ -11,18 +11,26 @@ def add_algorithm_interfaces_to_jobs(apps, _schema_editor): ) Job = apps.get_model("algorithms", "Job") # noqa: N806 - jobs = Job.objects.select_related("algorithm_image__algorithm").all() + jobs = ( + Job.objects.select_related("algorithm_image__algorithm") + .prefetch_related("inputs", "outputs") + .all() + ) for job in jobs: + inputs = [input.interface for input in job.inputs.all()] + outputs = [output.interface for output in job.outputs.all()] + interface = get_existing_interface_for_inputs_and_outputs( - inputs=job.inputs.all(), outputs=job.outputs.all() + model=AlgorithmInterface, inputs=inputs, outputs=outputs ) if not interface: interface = AlgorithmInterface.objects.create() - interface.inputs.set(job.inputs.all()) - interface.outputs.set(job.outputs.all()) + interface.inputs.set(inputs) + interface.outputs.set(outputs) job.algorithm_interface = interface job.algorithm_image.algorithm.interfaces.add(interface) + jobs.bulk_update(jobs, ["algorithm_interface"])