From d95158a8874a3e6f10189b48ba59fe10df6c9157 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sun, 10 Nov 2024 09:12:11 +0100 Subject: [PATCH] u-u: reload the "email.errors" package to workaround (LP: 2080940) This commit works around an issue when python itself is upgraded by u-u and the content of email.message now needs a newer email.errors but u-u already (implicitely) loaded that module so there is a old version in sys.modules. See https://github.com/python/cpython/issues/124170 and https://bugs.launchpad.net/ubuntu/+source/python3.8/+bug/2080940 for details. Thanks to Julian Klode for his excellent analysis. --- test/test_base.py | 2 +- unattended-upgrade | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test_base.py b/test/test_base.py index a9e6f706..11b0335c 100644 --- a/test/test_base.py +++ b/test/test_base.py @@ -65,7 +65,7 @@ def make_fake_aptroot(self, template=None, fake_pkgs=[]): self.addCleanup(shutil.rmtree, tmpdir) aptroot = os.path.join(tmpdir, "aptroot") shutil.copytree(template, aptroot) - # apt warns if this dir does not exist + # apt warns if this dir does not existg os.makedirs(os.path.join(aptroot, "etc/apt/preferences.d")) # fake dpkg status mock_dpkg_status = os.path.join(aptroot, "var/lib/dpkg/status") diff --git a/unattended-upgrade b/unattended-upgrade index 86358b19..c37b8d37 100755 --- a/unattended-upgrade +++ b/unattended-upgrade @@ -28,6 +28,7 @@ import copy import datetime import errno import email.charset +import email.errors import fcntl import fnmatch import gettext @@ -40,6 +41,7 @@ import grp import inspect import io from importlib.abc import Loader +import importlib import importlib.util import locale import logging @@ -1630,6 +1632,9 @@ def _send_mail_using_sendmail(from_address, to_address, subject, body): [SENDMAIL_BINARY, "-oi", "-t"], stdin=subprocess.PIPE, universal_newlines=True) assert sendmail.stdin # mypy + # workaround LP:2080940, email.errors changes as part of a security + # update in python itself and we need the new version + importlib.reload(email.errors) sendmail.stdin.write(msg.as_string()) sendmail.stdin.close() ret = sendmail.wait()