From 3e752d5f27f834cf53604323e68ba466cf389584 Mon Sep 17 00:00:00 2001 From: Touchstone64 <57038415+Touchstone64@users.noreply.github.com> Date: Fri, 19 Apr 2024 18:57:54 +0100 Subject: [PATCH] Fix: stop maxresults from overwriting previous results #1393 (#1394) * Fix: stop maxresults from overwriting previous results * Added test for use of maxresults in fetchItems #1393 * Removed the need for last_container_size #1393 * Renamed collections to better represen what is being tested * Renamed collections to better represent what is being tested #1393 * Update tests/test_library.py with cleaner test Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> --------- Co-authored-by: Graham Thompson Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> --- plexapi/base.py | 10 +++++----- tests/test_library.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/plexapi/base.py b/plexapi/base.py index 0852426d..d35ea8f1 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -283,6 +283,11 @@ class PlexObject: results.extend(subresults) + container_start += container_size + + if container_start > total_size: + break + wanted_number_of_items = total_size - offset if maxresults is not None: wanted_number_of_items = min(maxresults, wanted_number_of_items) @@ -291,11 +296,6 @@ class PlexObject: if wanted_number_of_items <= len(results): break - container_start += container_size - - if container_start > total_size: - break - return results def fetchItem(self, ekey, cls=None, **kwargs): diff --git a/tests/test_library.py b/tests/test_library.py index e3237f43..261f6371 100644 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -120,6 +120,16 @@ def test_library_fetchItem(plex, movie): assert item1 == item2 == movie +def test_library_fetchItems_with_maxresults(plex, tvshows): + items = tvshows.searchEpisodes() + assert len(items) > 5 + size = len(items) - 5 + ratingKeys = [item.ratingKey for item in items] + items1 = plex.fetchItems(ekey=ratingKeys, container_size=size) + items2 = plex.fetchItems(ekey=ratingKeys, container_size=size, maxresults=len(items)) + assert items1 == items2 == items + + def test_library_onDeck(plex, movie): movie.updateProgress(movie.duration // 4) # set progress to 25% assert movie in plex.library.onDeck()