From 8f3235cf29ad46287d97a09a5b639e1273ea16f0 Mon Sep 17 00:00:00 2001 From: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> Date: Thu, 12 Mar 2026 11:22:41 -0600 Subject: [PATCH 1/5] Add scan_date to import settings if overridden --- dojo/importers/base_importer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dojo/importers/base_importer.py b/dojo/importers/base_importer.py index 7734fc42d93..13447058a66 100644 --- a/dojo/importers/base_importer.py +++ b/dojo/importers/base_importer.py @@ -463,6 +463,7 @@ def update_import_history( import_settings["close_old_findings"] = self.close_old_findings_toggle import_settings["push_to_jira"] = self.push_to_jira import_settings["tags"] = self.tags + import_settings["scan_date"] = self.scan_date if self.scan_date_override else None if settings.V3_FEATURE_LOCATIONS: # Add the list of locations that were added exclusively at import time if len(self.endpoints_to_add) > 0: From e44463c1f8124d573fd18488fd2b54ada6657a49 Mon Sep 17 00:00:00 2001 From: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> Date: Wed, 25 Mar 2026 15:44:16 -0600 Subject: [PATCH 2/5] Fix datetime JSON serialization in import_settings Convert scan_date to ISO format string before storing in import_settings dict, which gets JSON-serialized. Raw datetime objects cause "TypeError: Object of type datetime is not JSON serializable". Co-Authored-By: Claude Opus 4.6 (1M context) --- dojo/importers/base_importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dojo/importers/base_importer.py b/dojo/importers/base_importer.py index 13447058a66..d6b63ee339c 100644 --- a/dojo/importers/base_importer.py +++ b/dojo/importers/base_importer.py @@ -463,7 +463,7 @@ def update_import_history( import_settings["close_old_findings"] = self.close_old_findings_toggle import_settings["push_to_jira"] = self.push_to_jira import_settings["tags"] = self.tags - import_settings["scan_date"] = self.scan_date if self.scan_date_override else None + import_settings["scan_date"] = self.scan_date.isoformat() if self.scan_date_override else None if settings.V3_FEATURE_LOCATIONS: # Add the list of locations that were added exclusively at import time if len(self.endpoints_to_add) > 0: From a2a694c3703e3c7d03150bbb92fc38a2a8fa1ec6 Mon Sep 17 00:00:00 2001 From: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> Date: Wed, 25 Mar 2026 17:44:35 -0600 Subject: [PATCH 3/5] Add unit tests for scan_date in import_settings Tests both cases: - User supplies scan_date: verifies it's stored as ISO string - No scan_date supplied: verifies it's stored as None Both tests also verify import_settings remains JSON-serializable. Co-Authored-By: Claude Opus 4.6 (1M context) --- unittests/test_update_import_history.py | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/unittests/test_update_import_history.py b/unittests/test_update_import_history.py index 8f263bb2a79..c47369a79b1 100644 --- a/unittests/test_update_import_history.py +++ b/unittests/test_update_import_history.py @@ -1,4 +1,6 @@ +import json import logging +from datetime import datetime from unittest.mock import patch from django.contrib.auth.models import User as DjangoUser @@ -149,3 +151,29 @@ def test_precheck_filters_out_deleted_findings_allows_successful_bulk(self): expected = (len(new_findings) - 1) + (len(closed_findings) - 1) created = Test_Import_Finding_Action.objects.filter(test_import=test_import).count() self.assertEqual(created, expected) + + def test_import_settings_scan_date_when_user_supplies_scan_date(self): + """When the user supplies a scan_date, import_settings should contain the ISO-formatted date.""" + user_scan_date = datetime(2025, 6, 15, 12, 0, 0, tzinfo=timezone.utc) + self.importer.scan_date = user_scan_date + self.importer.scan_date_override = True + + new_findings = self._create_findings(1) + test_import = self.importer.update_import_history(new_findings=new_findings) + + settings = test_import.import_settings + # Verify import_settings is JSON-serializable (the original bug) + json.dumps(settings) + self.assertEqual(settings["scan_date"], user_scan_date.isoformat()) + + def test_import_settings_scan_date_when_no_scan_date_supplied(self): + """When no scan_date override is provided, import_settings should have scan_date as None.""" + self.importer.scan_date_override = False + + new_findings = self._create_findings(1) + test_import = self.importer.update_import_history(new_findings=new_findings) + + settings = test_import.import_settings + # Verify import_settings is JSON-serializable + json.dumps(settings) + self.assertIsNone(settings["scan_date"]) From ce3dd1ba2a70c74f977f131af7adc8fc7cd526bb Mon Sep 17 00:00:00 2001 From: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> Date: Wed, 25 Mar 2026 23:50:28 -0600 Subject: [PATCH 4/5] Fix timezone import in scan_date test Use datetime.timezone.utc instead of django.utils.timezone.utc which doesn't exist. Co-Authored-By: Claude Opus 4.6 (1M context) --- unittests/test_update_import_history.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/test_update_import_history.py b/unittests/test_update_import_history.py index c47369a79b1..7ece7a094fe 100644 --- a/unittests/test_update_import_history.py +++ b/unittests/test_update_import_history.py @@ -1,6 +1,6 @@ import json import logging -from datetime import datetime +from datetime import datetime, timezone as dt_timezone from unittest.mock import patch from django.contrib.auth.models import User as DjangoUser @@ -154,7 +154,7 @@ def test_precheck_filters_out_deleted_findings_allows_successful_bulk(self): def test_import_settings_scan_date_when_user_supplies_scan_date(self): """When the user supplies a scan_date, import_settings should contain the ISO-formatted date.""" - user_scan_date = datetime(2025, 6, 15, 12, 0, 0, tzinfo=timezone.utc) + user_scan_date = datetime(2025, 6, 15, 12, 0, 0, tzinfo=dt_timezone.utc) self.importer.scan_date = user_scan_date self.importer.scan_date_override = True From 4a82822fad1d6d5c663aa825bdac9199fed57810 Mon Sep 17 00:00:00 2001 From: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> Date: Wed, 25 Mar 2026 23:54:08 -0600 Subject: [PATCH 5/5] Fix ruff lint: import sorting and use datetime.UTC alias Co-Authored-By: Claude Opus 4.6 (1M context) --- unittests/test_update_import_history.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/test_update_import_history.py b/unittests/test_update_import_history.py index 7ece7a094fe..d4192281985 100644 --- a/unittests/test_update_import_history.py +++ b/unittests/test_update_import_history.py @@ -1,6 +1,6 @@ import json import logging -from datetime import datetime, timezone as dt_timezone +from datetime import UTC, datetime from unittest.mock import patch from django.contrib.auth.models import User as DjangoUser @@ -154,7 +154,7 @@ def test_precheck_filters_out_deleted_findings_allows_successful_bulk(self): def test_import_settings_scan_date_when_user_supplies_scan_date(self): """When the user supplies a scan_date, import_settings should contain the ISO-formatted date.""" - user_scan_date = datetime(2025, 6, 15, 12, 0, 0, tzinfo=dt_timezone.utc) + user_scan_date = datetime(2025, 6, 15, 12, 0, 0, tzinfo=UTC) self.importer.scan_date = user_scan_date self.importer.scan_date_override = True