locale.Error: unsupported locale setting

Bug #2020064 reported by teluka
26
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Landscape Client
Fix Released
Undecided
Unassigned
landscape-client (Ubuntu)
In Progress
Undecided
Mitch Burton
Focal
Fix Committed
Undecided
Unassigned

Bug Description

[ Impact ]

 * When the C.UTF-8 locales is not installed, landscape-client's package
   reporter service fails to start:

Traceback (most recent call last):
  File "/usr/bin/landscape-package-reporter", line 10, in <module>
    main(sys.argv[1:])
  File "/usr/lib/python3/dist-packages/landscape/client/package/reporter.py", line 872, in main
    locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))
  File "/usr/lib/python3.8/locale.py", line 608, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

 * This prevents landscape-client from reporting packages, preventing
   all subsequent package activities.

[ Test Plan ]

 * Edit /etc/default/locale to contain LANG=en_GB.UTF-8
 * Run `sudo dpkg-reconfigure locales` and select only en_GB.UTF-8 and select
   en_GB.UTF-8 as default locale
 * ensure en_GB.UTF-8 is the _only_ selected locale, unselect other locales, en_US.UTF-8 in particular.
 * sudo apt install landscape-client
 * Attempt to start package-reporter:

   sudo landscape-package-reporter

   Package Reporter should start without any exceptions. There will be no output
   and the process will not exit unless killed.

 * Register landscape-client with landscape server and wait for the package
   reporter log to appear at /var/log/landscape/package-reporter.log. The log
   should not contain any errors.

 * Test again using a non-UTF-8 locale setting instead of en_GB.UTF-8

[ Where problems could occur ]

 * As this is a reversion of a previous fix for a bug regarding locales, that
   issue might re-occur with non-UTF-8 locales. A comment in LP: #1827857 claims
   this has been fixed in python-apt, though.

 * Packages with control file fields containing non-ASCII characters may be
   reported incorrectly. The Debian Policy Manual says that package names cannot
   contain these but other fields might,

[ Other Info ]

  <ORIGINAL BUG REPORT FOLLOWS>

OS: Ubuntu 20.04.6 LTS
Landscape client: 23.02-0ubuntu1

Due to missing locale, the landscape client couldn't report the list of installed packages to the landscape server (SAAS).

2023-05-10 17:23:10,675 WARNING [MainThread] Package reporter output:
b'Traceback (most recent call last):
  File "/usr/bin/landscape-package-reporter", line 10, in <module>
    main(sys.argv[1:])
  File "/usr/lib/python3/dist-packages/landscape/client/package/reporter.py", line 872, in main
    locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))
  File "/usr/lib/python3.8/locale.py", line 608, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
'

As a result, the server kept reporting available updates for the machine and when the update was triggered it failed with the following error reported in the task activity.

"Package data has changed. Please retry the operation."

For example on the affected client machine the "apt list --installed | grep dnsmasq-base" gives the output
"dnsmasq-base/focal-updates,focal-security,now 2.80-1.1ubuntu1.7 amd64

However, landscape server keeps reporting that update (2.80-1.1ubuntu1.7) is available.

Related branches

Revision history for this message
Juanmi Taboada (juanmitaboada) wrote :

I think the client machine should address this bug. A hint to resolve it could be:
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=C.UTF-8

Landscape Client could also try to prevent future failures when detected by applying the solution proposed above:

@@ -3,6 +3,7 @@
 except ImportError:
     import urllib.parse as urlparse

+import subprocess
 import locale
 import logging
 import time
@@ -943,7 +944,12 @@
 def main(args):
     # Force UTF-8 encoding only for the reporter, thus allowing libapt-pkg to
     # return unmangled descriptions.
- locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))
+ try:
+ locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))
+ except locale.Error:
+ subprocess.run(["sudo", "locale-gen", "en_US.UTF-8"], check=True)
+ subprocess.run(["sudo", "update-locale", "LANG=C.UTF-8"], check=True)
+ raise

     if "FAKE_GLOBAL_PACKAGE_STORE" in os.environ:
         return run_task_handler(FakeGlobalReporter, args)

There is a PR with this proposed solution at:
https://github.com/CanonicalLtd/landscape-client/pull/161

Changed in landscape-client:
status: New → Confirmed
Revision history for this message
Juanmi Taboada (juanmitaboada) wrote :

I will go with Mitch's suggestion to address this issue through the postinst script during package installation.

Revision history for this message
Michael Atkins (neroprotagonist) wrote :

I had the same error on one client machine and not another one even though both machines had LANG=en_GB.UTF-8 in /etc/default/locale and ran identical python version 3.8.10.

After some debugging using strace I found that the solution was to install/configure the en_US.UTF-8 locale using
dpkg-reconfigure locales
and making sure the en_US.UTF-8 was selected.

Also, I don't think a fix should alter the locale on a client machine (i.e. using update-locale) given that the whole point in locales is to support different regions and you would prevent the client from achieving this.

Changed in landscape-client (Ubuntu):
status: New → In Progress
assignee: nobody → Mitch Burton (mitchburton)
description: updated
Changed in landscape-client:
status: Confirmed → Fix Released
Revision history for this message
Simon Quigley (tsimonq2) wrote :

I do believe I already sponsored this :)

Revision history for this message
Timo Aaltonen (tjaalton) wrote : Please test proposed package

Hello teluka, or anyone else affected,

Accepted landscape-client into focal-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/landscape-client/23.02-0ubuntu1~20.04.5 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-focal to verification-done-focal. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-focal. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in landscape-client (Ubuntu Focal):
status: New → Fix Committed
tags: added: verification-needed verification-needed-focal
Revision history for this message
Mitch Burton (mitchburton) wrote :

I tested on Focal with version 23.02-0ubuntu1~20.04.5.

Setting locale to en_GB.UTF-8 and running landscape-package-reporter did not result in any errors. Registering the client and allowing package reporting to run did not result in any errors.

I repeated this test with the en_GB.ISO-8859-15 and it was also successful.

tags: added: verification-done verification-done-focal
removed: verification-needed verification-needed-focal
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

So this comment[1] states that that bug is fixed with python3-apt 2.0.0. That is the version in focal:

$ rmadison python3-apt|grep focal
 python3-apt | 2.0.0 | focal | amd64, arm64, armhf, i386, ppc64el, riscv64, s390x
 python3-apt | 2.0.0ubuntu0.20.04.3 | focal-security | amd64, arm64, armhf, i386, ppc64el, riscv64, s390x
 python3-apt | 2.0.1ubuntu0.20.04.1 | focal-updates | amd64, arm64, armhf, i386, ppc64el, riscv64, s390x

Furthermore, landscape-client in jammy and later do NOT have the patch from this bug here, and are still setting the locale to C in that main method.

So my questions are:
a) do we need this landscape-client fix for focal? Can we still reproduce the problem in a focal up-to-date system?
b) why is this patch not needed for jammy and later, do we know?

1. https://bugs.launchpad.net/ubuntu/+source/landscape-client/+bug/1827857/comments/4

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

For what is worth, I used landscape-client 23.02-0ubuntu1~20.04.4 (from current updates, not proposed), and I don't see a crash. Maybe something is missing from the test plan, like the removal of some locale/langpack package, or the fix isn't needed anymore?

ubuntu@f:~$ locale
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=
ubuntu@f:~$ apt-cache policy landscape-client
landscape-client:
  Installed: 23.02-0ubuntu1~20.04.4
  Candidate: 23.02-0ubuntu1~20.04.4
  Version table:
 *** 23.02-0ubuntu1~20.04.4 500
        500 http://br.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     19.12-0ubuntu4 500
        500 http://br.archive.ubuntu.com/ubuntu focal/main amd64 Packages
ubuntu@f:~$ sudo -u landscape landscape-package-reporter
ubuntu@f:~$

The package reporter logs are also clean:

ubuntu@f:~$ cat /var/log/landscape/package-reporter.log
2025-04-25 17:56:59,103 INFO [MainThread] Downloaded hash=>id database from https://landscape.canonical.com/hash-id-databases/af6f2dcf-1967-11de-8dd0-001a4b4d8d10_focal_amd64
2025-04-25 17:56:59,198 WARNING [MainThread] Removing cached hash=>id database /var/lib/landscape/client/package/hash-id/af6f2dcf-1967-11de-8dd0-001a4b4d8d10_focal_amd64
2025-04-25 17:57:04,118 INFO [MainThread] Queuing request for package hash => id translation on 500 hash(es).
2025-04-25 17:57:42,005 INFO [MainThread] Queuing message with changes in known packages: 453 installed, 99693 available, 17 available upgrades, 0 locked, 0 autoremovable, 41878 security, 0 not installed, 0 not available, 0 not available upgrades, 0 not locked, 0 not autoremovable, 0 not security.
2025-04-25 17:57:52,782 INFO [MainThread] Downloaded hash=>id database from https://landscape.canonical.com/hash-id-databases/af6f2dcf-1967-11de-8dd0-001a4b4d8d10_focal_amd64
2025-04-25 17:57:57,835 INFO [MainThread] Queuing request for package hash => id translation on 10291 hash(es).
2025-04-25 17:59:15,199 INFO [MainThread] Received 500 package hash => id translations, 0 hashes are unknown.
2025-04-25 17:59:58,113 INFO [MainThread] Queuing message with changes in known packages: 6 installed, 496 available, 0 available upgrades, 0 locked, 0 autoremovable, 155 security, 0 not installed, 0 not available, 0 not available upgrades, 0 not locked, 0 not autoremovable, 0 not security.

Revision history for this message
Mitch Burton (mitchburton) wrote :

I've just re-done the testing on focal and jammy and shown that it still exists, but does require one step that was not very clear in the testing plan.

When running `sudo dpkg-reconfigure locales` on a freshly created LXD container of focal or jammy, not only do you need to select en_GB.UTF-8, you need to _unselect_ en_US.UTF-8. Essentially en_GB.UTF-8 needs to be absolutely the only selected locale.

To answer above questions: yes, I think this needs to be fixed on jammy as well. In my testing, it does not appear to affect noble and later.

description: updated
Revision history for this message
Arif Ali (arif-ali) wrote :

We've also had an occurrence where this is an issue with jammy also where the locale on the nodes is LANG=en_GB.UTF-8, it's been reported that it will howveer work with LANG=C.UTF-8.

Excerpt from the log below

2025-04-30 08:26:14,871 WARNING [MainThread] Package reporter output:
b'Traceback (most recent call last):\n File "/usr/bin/landscape-package-reporter", line 10, in <module>\n main(sys.argv[1:])\n File "/usr/lib/python3/dist-packages/landscape/client/package/reporter.py", line 872, in main\n locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))\n File "/usr/lib/python3.10/locale.py", line 620, in setlocale\n return _setlocale(category, locale)\nlocale.Error: unsupported locale setting\n'

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

> To answer above questions: yes, I think this needs to be fixed on jammy as well.

This means I cannot release the focal package yet, because users then who upgrade to jammy will regress. And there is a focal upload in unapproved waiting to be accepted.

This is quite entangled :/

This is the, er, landscape:
landscape-client | 14.01-0ubuntu3 | trusty | source
landscape-client | 14.12-0ubuntu6.14.04.4 | trusty-updates | source
landscape-client | 16.03-0ubuntu2 | xenial | source
landscape-client | 16.03-0ubuntu2.16.04.8 | xenial-updates | source
landscape-client | 18.01-0ubuntu3 | bionic | source
landscape-client | 18.01-0ubuntu3.6 | bionic-updates | source
landscape-client | 19.12-0ubuntu4 | focal | source
landscape-client | 19.12-0ubuntu13 | jammy | source
landscape-client | 23.02-0ubuntu1~20.04.4 | focal-updates | source
landscape-client | 23.02-0ubuntu1~20.04.5 | focal-proposed | source
landscape-client | 23.02-0ubuntu1~20.04.6 | focal/unapproved/751f40bd | source
landscape-client | 23.02-0ubuntu1~22.04.4 | jammy-updates | source
landscape-client | 23.02-0ubuntu1~22.04.5 | jammy-proposed | source
landscape-client | 24.02-0ubuntu5 | noble | source
landscape-client | 24.02-0ubuntu5.3 | noble-updates | source
landscape-client | 24.02-0ubuntu5.4 | noble-proposed | source
landscape-client | 24.08-0ubuntu2 | oracular | source
landscape-client | 24.08-0ubuntu2.1 | oracular-updates | source
landscape-client | 24.08-0ubuntu2.2 | oracular-proposed | source
landscape-client | 24.12-0ubuntu2 | plucky | source
landscape-client | 24.12-0ubuntu2 | questing | source

Let me check if we can release the packages already in proposed for jammy, noble, oracular. That would "make up some space".

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Ugh, so, from https://bugs.launchpad.net/landscape-client/+bug/2087852/comments/20:

> I'm happy with that assessment. So the SRU for Focal (once verified) and Jammy will proceed, while noble
> will be blocked on this?

Also not an immediate path forward.

Revision history for this message
Mitch Burton (mitchburton) wrote :

Okay, so LP: #2087852 is a blocker on this, and therefore has highest priority for resolution, from my perspective.

Landscape team had a discussion yesterday regarding what the "correct" behaviour should be. We'll be producing an upstream fix sometime in the next few days. I'll take care of producing patches for every supported ubuntu version, plus focal. These patches will supersede whatever is currently in-flight for LP: #2087852.

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.