Skip to content

Commit

Permalink
Remove naive format warnings during import (#8527)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maffooch authored Aug 21, 2023
1 parent 53442b8 commit 7ff11b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions dojo/importers/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ def create_test(self, scan_type, test_type_name, engagement, lead, environment,
if created:
logger.info('Created new Test_Type with name %s because a report is being imported', test_type.name)

if scan_date and not scan_date.tzinfo:
scan_date = timezone.make_aware(scan_date)

if now and not now.tzinfo:
now = timezone.make_aware(now)

test = Test(
title=title,
engagement=engagement,
lead=lead,
test_type=test_type,
scan_type=scan_type,
target_start=scan_date if scan_date else now.date(),
target_end=scan_date if scan_date else now.date(),
target_start=scan_date or now,
target_end=scan_date or now,
environment=environment,
percent_complete=100,
version=version,
Expand Down
6 changes: 5 additions & 1 deletion dojo/importers/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.exceptions import ValidationError
from django.core.exceptions import MultipleObjectsReturned
from django.conf import settings
from django.utils.timezone import make_aware
from dojo.decorators import dojo_async_task
from dojo.celery import app
from dojo.endpoint.utils import endpoint_get_or_create
Expand All @@ -21,7 +22,10 @@ def update_timestamps(test, version, branch_tag, build_id, commit_hash, now, sca
if test.engagement.engagement_type == 'CI/CD':
test.engagement.target_end = max_safe([scan_date.date(), test.engagement.target_end])

test.target_end = max_safe([scan_date, test.target_end])
max_test_start_date = max_safe([scan_date, test.target_end])
if not max_test_start_date.tzinfo:
max_test_start_date = make_aware(max_test_start_date)
test.target_end = max_test_start_date

if version:
test.version = version
Expand Down

0 comments on commit 7ff11b5

Please sign in to comment.