Skip to content

Commit 22e0e91

Browse files
authored
Add config option to disable auto-reloading (#1187)
1 parent 01f7ee5 commit 22e0e91

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

docs/configuration.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ Section [plexapi] Options
5555
Timeout in seconds to use when making requests to the Plex Media Server or Plex Client
5656
resources (default: 30).
5757

58+
**autoreload**
59+
By default PlexAPI will automatically :func:`~plexapi.base.PlexObject.reload` any :any:`PlexPartialObject`
60+
when accessing a missing attribute. When this option is set to `false`, automatic reloading will be
61+
disabled and :func:`~plexapi.base.PlexObject.reload` must be called manually (default: true).
62+
5863
**enable_fast_connect**
5964
By default Plex will be trying to connect with all available connection methods simultaneously,
6065
combining local and remote addresses, http and https, and be waiting for all connection to
6166
establish (or fail due to timeout / any other error), this can take long time when you're trying
6267
to connect to your Plex Server outside of your home network.
6368

6469
When the options is set to `true` the connection procedure will be aborted with first successfully
65-
established connection.
70+
established connection (default: false).
6671

6772

6873
Section [auth] Options

plexapi/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from urllib.parse import urlencode
55
from xml.etree import ElementTree
66

7-
from plexapi import X_PLEX_CONTAINER_SIZE, log, utils
7+
from plexapi import CONFIG, X_PLEX_CONTAINER_SIZE, log, utils
88
from plexapi.exceptions import BadRequest, NotFound, UnknownType, Unsupported
99
from plexapi.utils import cached_property
1010

@@ -50,9 +50,14 @@ def __init__(self, server, data, initpath=None, parent=None):
5050
self._initpath = initpath or self.key
5151
self._parent = weakref.ref(parent) if parent is not None else None
5252
self._details_key = None
53-
self._overwriteNone = True # Allow overwriting previous attribute values with `None` when manually reloading
54-
self._autoReload = True # Automatically reload the object when accessing a missing attribute
55-
self._edits = None # Save batch edits for a single API call
53+
54+
# Allow overwriting previous attribute values with `None` when manually reloading
55+
self._overwriteNone = True
56+
# Automatically reload the object when accessing a missing attribute
57+
self._autoReload = CONFIG.get('plexapi.autoreload', True, bool)
58+
# Attribute to save batch edits for a single API call
59+
self._edits = None
60+
5661
if data is not None:
5762
self._loadData(data)
5863
self._details_key = self._buildDetailsKey()

plexapi/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from collections import defaultdict
44
from configparser import ConfigParser
55

6+
from plexapi import utils
7+
68

79
class PlexConfig(ConfigParser):
810
""" PlexAPI configuration object. Settings are stored in an INI file within the
@@ -35,7 +37,7 @@ def get(self, key, default=None, cast=None):
3537
# Second: check the config file has attr
3638
section, name = key.lower().split('.')
3739
value = self.data.get(section, {}).get(name, default)
38-
return cast(value) if cast else value
40+
return utils.cast(cast, value) if cast else value
3941
except: # noqa: E722
4042
return default
4143

0 commit comments

Comments
 (0)