Skip to content
Snippets Groups Projects
Commit 14d2f39a authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Remove configurations before cleaning up archived workers

parent 7202709f
No related branches found
No related tags found
1 merge request!2432Remove configurations before cleaning up archived workers
...@@ -304,6 +304,10 @@ class Command(BaseCommand): ...@@ -304,6 +304,10 @@ class Command(BaseCommand):
continue continue
self.stdout.write(f"Removing worker {worker.name} ({worker.id})") self.stdout.write(f"Removing worker {worker.name} ({worker.id})")
# worker.delete would only try to set configurations to None on the WorkerRuns instead of deleting them,
# which could cause errors on unique constraints. We delete those runs instead, and do so with _raw_delete
# so that we don't update or delete anything more than worker runs.
WorkerRun.objects.filter(configuration__worker=worker)._raw_delete(using="default")
worker.delete() worker.delete()
deleted += 1 deleted += 1
......
...@@ -1124,6 +1124,20 @@ class TestCleanupCommand(FixtureTestCase): ...@@ -1124,6 +1124,20 @@ class TestCleanupCommand(FixtureTestCase):
removable_worker.archived = datetime.now(timezone.utc) - timedelta(days=11) removable_worker.archived = datetime.now(timezone.utc) - timedelta(days=11)
removable_worker.save() removable_worker.save()
# Create a process where a worker version is used both with and without a configuration from this worker
# This could lead to integrity errors with the default Django removal, as the configuration would be removed
# from the WorkerRuns, so there would be 2 runs with the same version and no configuration when they should be unique
process = self.corpus.processes.create(mode=ProcessMode.Workers, creator=self.superuser)
version = removable_worker.versions.first()
process.worker_runs.create(version=version)
process.worker_runs.create(
version=version,
configuration=removable_worker.configurations.create(
name="Some configuration",
configuration={},
),
)
# This worker cannot be cleaned up because it is used in ML results # This worker cannot be cleaned up because it is used in ML results
used_worker = Worker.objects.get(slug="reco") used_worker = Worker.objects.get(slug="reco")
self.assertTrue(used_worker.versions.all().in_use()) self.assertTrue(used_worker.versions.all().in_use())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment