Skip to content

Commit

Permalink
u-u: reload the "email.errors" package to workaround (LP: 2080940)
Browse files Browse the repository at this point in the history
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 python/cpython#124170 and
https://bugs.launchpad.net/ubuntu/+source/python3.8/+bug/2080940
for details.

Thanks to Julian Klode for his excellent analysis.
  • Loading branch information
mvo5 committed Nov 10, 2024
1 parent edb2f8b commit d95158a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions unattended-upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import copy
import datetime
import errno
import email.charset
import email.errors
import fcntl
import fnmatch
import gettext
Expand All @@ -40,6 +41,7 @@ import grp
import inspect
import io
from importlib.abc import Loader
import importlib
import importlib.util
import locale
import logging
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d95158a

Please sign in to comment.