From 7a1f0f6a8f6095b08638e843392a9dfbe3fdb977 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 3 Oct 2020 20:58:12 +1000 Subject: [PATCH] Fixed bug in Exif __delitem__ --- Tests/test_image.py | 3 +++ src/PIL/Image.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 89894c9a7..c949be08b 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -650,12 +650,14 @@ class TestImage: with Image.open("Tests/images/exif-72dpi-int.jpg") as im: # Little endian exif = im.getexif() assert 258 not in exif + assert 274 in exif assert 40960 in exif assert exif[40963] == 450 assert exif[11] == "gThumb 3.0.1" out = str(tmp_path / "temp.jpg") exif[258] = 8 + del exif[274] del exif[40960] exif[40963] = 455 exif[11] = "Pillow test" @@ -663,6 +665,7 @@ class TestImage: with Image.open(out) as reloaded: reloaded_exif = reloaded.getexif() assert reloaded_exif[258] == 8 + assert 274 not in reloaded_exif assert 40960 not in reloaded_exif assert reloaded_exif[40963] == 455 assert reloaded_exif[11] == "Pillow test" diff --git a/src/PIL/Image.py b/src/PIL/Image.py index a18a231d3..b864f7489 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -3466,7 +3466,8 @@ class Exif(MutableMapping): def __delitem__(self, tag): if self._info is not None and tag in self._info: del self._info[tag] - del self._data[tag] + else: + del self._data[tag] def __iter__(self): keys = set(self._data)