Skip to content

Conversation

kiblik
Copy link
Contributor

@kiblik kiblik commented Aug 15, 2025

TL;DR

During a deeper analysis of #12974 (why there are locale definitions in commands), I noticed that they are copy-paste leftovers and were never used. They can be removed.

Full story

I was trying to identify the reason for locale in those many commands which has never been used.

$ git log -p -S'locale = ' dojo/management/commands | grep 'locale'              
-locale = timezone(get_system_setting('time_zone'))
-locale = timezone(get_system_setting('time_zone'))
-locale = timezone(get_system_setting('time_zone'))
-locale = timezone(get_system_setting('time_zone'))
-                    current_scan.date = locale.localize(datetime.today())
-            msg += " was performed on " + locale.normalize(
-                                       date=locale.localize(datetime.today()))
-locale = timezone(get_system_setting('time_zone'))
-locale = timezone(get_system_setting('time_zone'))
+locale = timezone(get_system_setting('time_zone'))
+locale = timezone(get_system_setting('time_zone'))
+locale = timezone(get_system_setting('time_zone'))
+locale = timezone(get_system_setting('time_zone'))
+locale = timezone(get_system_setting('time_zone'))
+locale = timezone(settings.TIME_ZONE)
+locale = timezone(settings.TIME_ZONE)
+locale = timezone(settings.TIME_ZONE)
+locale = timezone(settings.TIME_ZONE)
-locale = timezone(settings.TIME_ZONE)
+locale = timezone(settings.TIME_ZONE)
+locale = timezone(settings.TIME_ZONE)
+locale = timezone(settings.TIME_ZONE)
+locale = timezone(settings.TIME_ZONE)
+                    current_scan.date = locale.localize(datetime.today())
+            msg += " was performed on " + locale.normalize(
+                                       date=locale.localize(datetime.today()))
git log -p -S'current_scan.date = locale' dojo/management/commands | grep index
index 119a633a21..0000000000
index 0000000000..196e37e26d

Unfortunately, I wasn't able to fully find full context

$ git checkout 196e37e26d                                                        
fatal: unable to read tree (196e37e26de63463986c412b9105feb73e975cbf)
$ git checkout 119a633a21          
fatal: unable to read tree (119a633a218a0ec7b6353c91c255281b23de860d)

But I have at least partial results

git log -p -S'current_scan.date = locale' dojo/management/commands | grep '^diff'
diff --git a/dojo/management/commands/run_scan.py b/dojo/management/commands/run_scan.py
diff --git a/dojo/management/commands/run_scan.py b/dojo/management/commands/run_scan.py
$ git show 196e37e26de63463986c412b9105feb73e975cbf | grep -C 3 locale
import dojo.settings as settings


locale = timezone(settings.TIME_ZONE)


"""
--
            for host in p_dict:
                current_scan = Scan.objects.get(id=p_dict[host]['scan_id'])
                if not current_scan.date:
                    current_scan.date = locale.localize(datetime.today())

                # For each host, save the IPScan and the date to the scan
                # to the db
--
            # necessary
            product = Product.objects.get(id=prod_id).name
            msg = "Hello, \n\nA port scan of the product " + product
            msg += " was performed on " + locale.normalize(
                current_scan.date).strftime("%A %B %d, %Y at %I:%M:%S %p")
            msg += "\nThe results of the scan show that the following ip "
            msg += "addresses have the following ports open: \n\n"
--
            # Create a Scan for each requested Scan (Scan Setting)
            scan = Scan.objects.create(scan_settings_id=s.id,
                                       protocol=s.protocol,
                                       date=locale.localize(datetime.today()))
            prod_id = str(s.product_id)
            list_addresses = s.addresses.strip().split(",")
            for line in list_addresses:

Summary

It was implemented as part of dojo/management/commands/run_scan.py and copy-pasted to many other commands where locale was not necessary. dojo/management/commands/run_scan.py is not there anymore, and locale is not needed in any of commands.

Copy link
Contributor

@Maffooch Maffooch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice analysis

Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@mtesauro mtesauro merged commit ce14434 into DefectDojo:dev Aug 22, 2025
85 checks passed
@kiblik kiblik deleted the commands_locale branch August 22, 2025 06:04
@valentijnscholten valentijnscholten changed the title fix(timezone/commands): Drop obsolite 'locale' definitions fix(timezone/commands): Drop obsolete 'locale' definitions Aug 24, 2025
@valentijnscholten valentijnscholten added this to the 2.50.0 milestone Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants