diff --git a/openedx/core/djangoapps/profile_images/images.py b/openedx/core/djangoapps/profile_images/images.py index 5d0c7bdd0a..1085fb147a 100644 --- a/openedx/core/djangoapps/profile_images/images.py +++ b/openedx/core/djangoapps/profile_images/images.py @@ -205,7 +205,8 @@ def _update_exif_orientation(exif, orientation): the exif orientation, return a new exif with the orientation set. """ exif_dict = piexif.load(exif) - exif_dict['0th'][piexif.ImageIFD.Orientation] = orientation + if orientation: + exif_dict['0th'][piexif.ImageIFD.Orientation] = orientation return piexif.dump(exif_dict) diff --git a/openedx/core/djangoapps/profile_images/tests/test_images.py b/openedx/core/djangoapps/profile_images/tests/test_images.py index b0134b731e..27b43a5b21 100644 --- a/openedx/core/djangoapps/profile_images/tests/test_images.py +++ b/openedx/core/djangoapps/profile_images/tests/test_images.py @@ -24,6 +24,7 @@ from ..images import ( validate_uploaded_image, _get_exif_orientation, _get_valid_file_types, + _update_exif_orientation ) from .helpers import make_image_file, make_uploaded_file @@ -186,6 +187,20 @@ class TestGenerateProfileImages(TestCase): for _, image in self._create_mocked_profile_images(imfile, requested_images): self.check_exif_orientation(image, None) + def test_update_exif_orientation_without_orientation(self): + """ + Test the update_exif_orientation without orientation will not throw exception. + """ + requested_images = {10: "ten.jpg"} + with make_image_file(extension='.jpg') as imfile: + for _, image in self._create_mocked_profile_images(imfile, requested_images): + self.check_exif_orientation(image, None) + exif = image.info.get('exif', piexif.dump({})) + self.assertEqual( + _update_exif_orientation(exif, None), + image.info.get('exif', piexif.dump({})) + ) + def _create_mocked_profile_images(self, image_file, requested_images): """ Create image files with mocked-out storage.