Skip to content

Commit

Permalink
Fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
amickan committed Dec 19, 2024
1 parent f57c1c7 commit d341afc
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"])


Expand Down

0 comments on commit d341afc

Please sign in to comment.