Skip to content

Accessing optional attributes results in an unnecessary reload #713

@Montellese

Description

@Montellese

Describe the issue

This is not a bug but a feature / improvement request.

I'm trying to retrieve all items from a library section e.g. all movies. Then I'm collecting all the information available for the retrieved movies which requires a reload for some of the attributes like Movie.roles because not all roles are present in the XML data received from the /library/sections/{id}/all endpoint. Since I'm not interested in all the extra stuff like On Deck, Related etc. I wanted to make use of the possibility to customize the used includeXYZ in PlexObject.reload() as introduced in #607. While the customized call to PlexObject.reload() works fine, in the end plexapi often ends up performing a full reload() anyway because I try to access an attribute of Movie or Video which is optional in the XML response like lastViewedAt (which is only provided if the movie has been viewed at least once). The problem is that for all unviewed movies Movie.lastViewedAt will be None and the Movie object will only be a partial object because I did a partial reload() so the logic in PlexObject.reload() will perform a full reload in addition to the customized partial reload() I executed before.

https://github.com/pkkid/python-plexapi/blob/2bde2344084721d7015167af4762d3bc397fe5d2/plexapi/base.py#L426-L442

Is there any way we can add a list of attributes to the specific media classes like Video, Movie etc. which contains all attributes which don't require a full reload() even if they are None or []?

PS: This does not only apply to lastViewedAt but also to collections, originalTitle and others.

Code snippets

The following code snippet first performs a customized reload() and then internally a full reload() if lastViewedAt is not set because the video has never been played / watched:

item.reload(includeOnDeck=False, includeRelated=False, includeReviews=False)
print(f"{item.title} last viewed at {item.lastViewedAt}")

Expected behavior

Only the customized reload() actually reloads the item while accessing lastViewedAt doesn't perform a full reload().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions