From 1ef518cc3e9efbe9d4c16aa3d36c6dc6db86798e Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 6 Jul 2020 10:35:54 -0700 Subject: [PATCH] Bug fix for empty albums --- osxphotos/_version.py | 2 +- osxphotos/albuminfo.py | 17 ++++++++++------- tests/test_catalina_10_15_5.py | 8 ++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 317a83e6..ff38ad1a 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.30.9" +__version__ = "0.30.10" diff --git a/osxphotos/albuminfo.py b/osxphotos/albuminfo.py index 8a59c06c..40ce5d72 100644 --- a/osxphotos/albuminfo.py +++ b/osxphotos/albuminfo.py @@ -48,13 +48,16 @@ class AlbumInfo: try: return self._photos except AttributeError: - uuid, sort_order = zip(*self._db._dbalbums_album[self.uuid]) - self._photos = self._db.photos(uuid=uuid) - # PhotosDB.photos does not preserve order when passing in list of uuids - # so need to build photo list one a time - # sort uuids by sort order - sorted_uuid = sorted(zip(sort_order, uuid)) - self._photos = [self._db.photos(uuid=[uuid])[0] for _, uuid in sorted_uuid] + if self.uuid in self._db._dbalbums_album: + uuid, sort_order = zip(*self._db._dbalbums_album[self.uuid]) + self._photos = self._db.photos(uuid=uuid) + # PhotosDB.photos does not preserve order when passing in list of uuids + # so need to build photo list one a time + # sort uuids by sort order + sorted_uuid = sorted(zip(sort_order, uuid)) + self._photos = [self._db.photos(uuid=[uuid])[0] for _, uuid in sorted_uuid] + else: + self._photos = [] return self._photos @property diff --git a/tests/test_catalina_10_15_5.py b/tests/test_catalina_10_15_5.py index 90a90c5a..aa1cbc2a 100644 --- a/tests/test_catalina_10_15_5.py +++ b/tests/test_catalina_10_15_5.py @@ -233,6 +233,14 @@ def test_album_sort_order(): uuids = [p.uuid for p in photos] assert uuids == ALBUM_SORT_ORDER +def test_album_empty_album(): + import osxphotos + + photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) + album = [a for a in photosdb.album_info if a.title == "EmptyAlbum"][0] + photos = album.photos + assert photos == [] + def test_attributes(): import datetime import osxphotos