Merge pull request #656 from JonnyWong16/feature/object_parent

Fix checking object parent when the weakref is dead
This commit is contained in:
JonnyWong16 2021-02-14 14:34:54 -08:00 committed by GitHub
commit f66624f2bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -124,9 +124,9 @@ class PlexObject(object):
See all possible `**kwargs*` in :func:`~plexapi.base.PlexObject.fetchItem`.
"""
obj = self
while obj._parent is not None:
while obj and obj._parent is not None:
obj = obj._parent()
if obj._checkAttrs(obj._data, **kwargs):
if obj and obj._checkAttrs(obj._data, **kwargs):
return True
return False

View file

@ -799,6 +799,16 @@ def test_video_Episode_hidden_season(episode):
show.defaultAdvanced()
def test_video_Episode_parent_weakref(show):
season = show.season(season=1)
episode = season.episode(episode=1)
assert episode._parent is not None
assert episode._parent() == season
episode = show.season(season=1).episode(episode=1)
assert episode._parent is not None
assert episode._parent() is None
# Analyze seems to fail intermittently
@pytest.mark.xfail
def test_video_Episode_analyze(tvshows):