Horizon dashboard crashes on non-exisiting TimeZones

Bug #2085126 reported by Harry Kodden
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
Undecided
Unassigned

Bug Description

On opening the 'Settings' form the top right menu, the user gets the settings page on which he can change password ar select a different timezone. The timezones that are presented are created from all existing timezones. However the locales may not be available for alle these timezones. For example when 'US/Samoa' is not present, the UI will crash.

Proposed change is to only present timezones to the user for which a locale settings is available

Example of Error:

FileNotFoundError at /settings/
[Errno 2] No such file or directory: '/usr/lib/python3/dist-packages/pytz/zoneinfo/US/Samoa'
Request Method: GET
Request URL: https://keystone.example.com/dashboard/settings/
Django Version: 4.2.15
Exception Type: FileNotFoundError
Exception Value:
[Errno 2] No such file or directory: '/usr/lib/python3/dist-packages/pytz/zoneinfo/US/Samoa'

This is proposed change:

NOTE: Sorry for formatting of below code, I can't get get spaces being respected by launchpad, Grrr

<pre>
a/openstack_dashboard/dashboards/settings/user/forms.py b/openstack_dashboard/dashboards/settings/user/forms.py
index 1c1f58dfa..d533ef3f6 100644
--- a/openstack_dashboard/dashboards/settings/user/forms.py
+++ b/openstack_dashboard/dashboards/settings/user/forms.py
@@ -82,8 +82,12 @@ class UserSettingsForm(forms.SelfHandlingForm):
             elif tz == "GMT":
                 tz_name = _("GMT")
             else:
- tz_label = babel.dates.get_timezone_location(
- tz, locale=babel_locale)
+ try:
+ tz_label = babel.dates.get_timezone_location(
+ tz, locale=babel_locale)
+ except:
+ continue
+
                 # Translators: UTC offset and timezone label
                 tz_name = _("%(offset)s: %(label)s") % {"offset": utc_offset,
                                                         "label": tz_label}
</pre>

This is intended code fragment:

        for tz, offset in self._sorted_zones():
            try:
                utc_offset = _("UTC %(hour)s:%(min)s") % {"hour": offset[:3],
                                                          "min": offset[3:]}
            except Exception:
                utc_offset = ""

            if tz == "UTC":
                tz_name = _("UTC")
            elif tz == "GMT":
                tz_name = _("GMT")
            else:
                try:
                    tz_label = babel.dates.get_timezone_location(
                       tz, locale=babel_locale)
                except:
                    continue

                # Translators: UTC offset and timezone label
                tz_name = _("%(offset)s: %(label)s") % {"offset": utc_offset,
                                                        "label": tz_label}
            timezones.append((tz, tz_name))

description: updated
description: updated
description: updated
description: updated
description: updated
description: updated
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/horizon/+/939546

Changed in horizon:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.opendev.org/c/openstack/horizon/+/939546
Committed: https://opendev.org/openstack/horizon/commit/5190d6e5540cb1344d48f603528ca0eb73ada436
Submitter: "Zuul (22348)"
Branch: master

commit 5190d6e5540cb1344d48f603528ca0eb73ada436
Author: Owen McGonagle <email address hidden>
Date: Fri Jan 17 11:59:29 2025 -0500

    Non-existent timezone fix

    Closes-Bug: #2085126
    Change-Id: I37c5462be8de39a7280208d55b64fc0430d0c584

Changed in horizon:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (stable/2025.1)

Fix proposed to branch: stable/2025.1
Review: https://review.opendev.org/c/openstack/horizon/+/946571

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (stable/2025.1)

Reviewed: https://review.opendev.org/c/openstack/horizon/+/946571
Committed: https://opendev.org/openstack/horizon/commit/c6bb2ef2b74ff36e24f0ff584f6a35eb8398a4ac
Submitter: "Zuul (22348)"
Branch: stable/2025.1

commit c6bb2ef2b74ff36e24f0ff584f6a35eb8398a4ac
Author: Owen McGonagle <email address hidden>
Date: Fri Jan 17 11:59:29 2025 -0500

    Non-existent timezone fix

    Closes-Bug: #2085126
    Change-Id: I37c5462be8de39a7280208d55b64fc0430d0c584
    (cherry picked from commit 5190d6e5540cb1344d48f603528ca0eb73ada436)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (stable/2024.2)

Fix proposed to branch: stable/2024.2
Review: https://review.opendev.org/c/openstack/horizon/+/946978

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (stable/2024.2)

Reviewed: https://review.opendev.org/c/openstack/horizon/+/946978
Committed: https://opendev.org/openstack/horizon/commit/9d37a15441b5268163c5dba67bc3dab7a640d8e0
Submitter: "Zuul (22348)"
Branch: stable/2024.2

commit 9d37a15441b5268163c5dba67bc3dab7a640d8e0
Author: Owen McGonagle <email address hidden>
Date: Fri Jan 17 11:59:29 2025 -0500

    Non-existent timezone fix

    Closes-Bug: #2085126
    Change-Id: I37c5462be8de39a7280208d55b64fc0430d0c584
    (cherry picked from commit 5190d6e5540cb1344d48f603528ca0eb73ada436)
    (cherry picked from commit c6bb2ef2b74ff36e24f0ff584f6a35eb8398a4ac)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.