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 <omcgo...@redhat.com>
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

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Dashboard (Horizon).
https://bugs.launchpad.net/bugs/2085126

Title:
  Horizon dashboard crashes on non-exisiting TimeZones

Status in OpenStack Dashboard (Horizon):
  Fix Released

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))

To manage notifications about this bug go to:
https://bugs.launchpad.net/horizon/+bug/2085126/+subscriptions


-- 
Mailing list: https://launchpad.net/~yahoo-eng-team
Post to     : yahoo-eng-team@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yahoo-eng-team
More help   : https://help.launchpad.net/ListHelp

Reply via email to