From 0a035184b78f0e8839e53b4ebf999c0ebdd93dfa Mon Sep 17 00:00:00 2001 From: dogboat Date: Wed, 1 Apr 2026 09:07:50 -0400 Subject: [PATCH 1/3] update migrate_endpoints_to_locations mgmt command to work when v3/locations enabled --- .../commands/migrate_endpoints_to_locations.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dojo/management/commands/migrate_endpoints_to_locations.py b/dojo/management/commands/migrate_endpoints_to_locations.py index d30fa121d3b..5efd6f47c7b 100644 --- a/dojo/management/commands/migrate_endpoints_to_locations.py +++ b/dojo/management/commands/migrate_endpoints_to_locations.py @@ -88,10 +88,11 @@ def _associate_location_with_findings(self, endpoint: Endpoint, location: Locati location.associate_with_product(product) def handle(self, *args, **options): - # Start off with the endpoint objects - it should everything we need - for endpoint in Endpoint.objects.all().iterator(): - # Get the URL object first - location = self._endpoint_to_url(endpoint) - # Associate the URL with the findings associated with the Findings - # the association to a finding will also apply to a product automatically - self._associate_location_with_findings(endpoint, location) + with Endpoint.allow_endpoint_init(): + # Start off with the endpoint objects - it should contain everything we need + for endpoint in Endpoint.objects.all().iterator(): + # Get the URL object first + location = self._endpoint_to_url(endpoint) + # Associate the URL with the findings associated with the Findings + # the association to a finding will also apply to a product automatically + self._associate_location_with_findings(endpoint, location) From e487b7aaefcbd7c9db5dee1e3e4d300671dc3c11 Mon Sep 17 00:00:00 2001 From: dogboat Date: Wed, 1 Apr 2026 09:36:17 -0400 Subject: [PATCH 2/3] include progress report on endpoint to location migration --- .../migrate_endpoints_to_locations.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/dojo/management/commands/migrate_endpoints_to_locations.py b/dojo/management/commands/migrate_endpoints_to_locations.py index 5efd6f47c7b..6444ed185ec 100644 --- a/dojo/management/commands/migrate_endpoints_to_locations.py +++ b/dojo/management/commands/migrate_endpoints_to_locations.py @@ -11,6 +11,8 @@ logger = logging.getLogger(__name__) +# Chunk size for DB cursor and progress report +CHUNK_SIZE = 1000 class Command(BaseCommand): @@ -88,11 +90,31 @@ def _associate_location_with_findings(self, endpoint: Endpoint, location: Locati location.associate_with_product(product) def handle(self, *args, **options): + # Allow endpoints to work with V3/Locations enabled with Endpoint.allow_endpoint_init(): + # Progress counter + i = 0 # Start off with the endpoint objects - it should contain everything we need - for endpoint in Endpoint.objects.all().iterator(): + queryset = Endpoint.objects.all() + # Grab the total count so we can communicate progress + endpoint_count = queryset.count() + + # Process each endpoint + for i, endpoint in enumerate(queryset.iterator(chunk_size=CHUNK_SIZE), 1): + # Progress report every chunk + if not i % CHUNK_SIZE: + self.stdout.write( + self.style.SUCCESS( + f"Migrated {i}/{endpoint_count} endpoints..." + ) + ) # Get the URL object first location = self._endpoint_to_url(endpoint) # Associate the URL with the findings associated with the Findings # the association to a finding will also apply to a product automatically self._associate_location_with_findings(endpoint, location) + self.stdout.write( + self.style.SUCCESS( + f"Migrated {i} total endpoints." + ) + ) From a22712b438fbf82c9b01b395b7711286745ce2f9 Mon Sep 17 00:00:00 2001 From: dogboat Date: Wed, 1 Apr 2026 09:44:38 -0400 Subject: [PATCH 3/3] linter fixes --- .../commands/migrate_endpoints_to_locations.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dojo/management/commands/migrate_endpoints_to_locations.py b/dojo/management/commands/migrate_endpoints_to_locations.py index 6444ed185ec..25c739abb0a 100644 --- a/dojo/management/commands/migrate_endpoints_to_locations.py +++ b/dojo/management/commands/migrate_endpoints_to_locations.py @@ -14,6 +14,7 @@ # Chunk size for DB cursor and progress report CHUNK_SIZE = 1000 + class Command(BaseCommand): """ @@ -105,8 +106,8 @@ def handle(self, *args, **options): if not i % CHUNK_SIZE: self.stdout.write( self.style.SUCCESS( - f"Migrated {i}/{endpoint_count} endpoints..." - ) + f"Migrated {i}/{endpoint_count} endpoints...", + ), ) # Get the URL object first location = self._endpoint_to_url(endpoint) @@ -115,6 +116,6 @@ def handle(self, *args, **options): self._associate_location_with_findings(endpoint, location) self.stdout.write( self.style.SUCCESS( - f"Migrated {i} total endpoints." - ) + f"Migrated {i} total endpoints.", + ), )