From 613d2fcdfa315e815893eea72d3ecb1d65809b9f 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. So instead import email as late as possible. 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. --- unattended-upgrade | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/unattended-upgrade b/unattended-upgrade index 86358b19..d5797d60 100755 --- a/unattended-upgrade +++ b/unattended-upgrade @@ -27,7 +27,6 @@ import contextlib import copy import datetime import errno -import email.charset import fcntl import fnmatch import gettext @@ -40,6 +39,7 @@ import grp import inspect import io from importlib.abc import Loader +import importlib import importlib.util import locale import logging @@ -71,7 +71,6 @@ except ImportError: from collections import defaultdict, namedtuple from datetime import date -from email.message import Message from gettext import gettext as _ from io import StringIO from optparse import ( @@ -1613,6 +1612,10 @@ def _send_mail_using_mailx(from_address, to_address, subject, body): def _send_mail_using_sendmail(from_address, to_address, subject, body): + # workaround LP:2080940, email.errors changes as part of a security + # update in python itself so import this as late as possible + import email.charset + from email.message import Message # type: (str, str, str, str) -> int # format as a proper mail msg = Message()