From 5f8cca44d996bcfa8d4abe9b9fa7cf92e1518c33 Mon Sep 17 00:00:00 2001 From: anatosun <33899455+anatosun@users.noreply.github.com> Date: Thu, 27 Nov 2025 00:44:01 +0100 Subject: [PATCH] Plex: fix collision in cache keys (#2638) --- music_assistant/providers/plex/__init__.py | 3 ++- music_assistant/providers/plex/helpers.py | 23 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/music_assistant/providers/plex/__init__.py b/music_assistant/providers/plex/__init__.py index 21bca993..3a9bc17c 100644 --- a/music_assistant/providers/plex/__init__.py +++ b/music_assistant/providers/plex/__init__.py @@ -126,7 +126,7 @@ async def setup( async def get_config_entries( # noqa: PLR0915 mass: MusicAssistant, - instance_id: str | None = None, # noqa: ARG001 + instance_id: str | None = None, action: str | None = None, values: dict[str, ConfigValueType] | None = None, ) -> tuple[ConfigEntry, ...]: @@ -276,6 +276,7 @@ async def get_config_entries( # noqa: PLR0915 server_http_ip, server_http_port, server_http_verify_cert, + instance_id, ) ): msg = "Unable to retrieve Servers and/or Music Libraries" diff --git a/music_assistant/providers/plex/helpers.py b/music_assistant/providers/plex/helpers.py index 0bd1645a..665026e1 100644 --- a/music_assistant/providers/plex/helpers.py +++ b/music_assistant/providers/plex/helpers.py @@ -22,11 +22,20 @@ async def get_libraries( local_server_ip: str, local_server_port: str, local_server_verify_cert: bool, + instance_id: str | None = None, ) -> list[str]: """ Get all music libraries for all plex servers. - Returns a dict of Library names in format {'servername / library name':'baseurl'} + Returns a list of Library names in format ['servername / library name', ...] + + :param mass: MusicAssistant instance. + :param auth_token: Authentication token for Plex server. + :param local_server_ssl: Whether to use SSL/HTTPS. + :param local_server_ip: IP address of the Plex server. + :param local_server_port: Port of the Plex server. + :param local_server_verify_cert: Whether to verify SSL certificate. + :param instance_id: Provider instance ID to use for cache isolation. """ cache_key = "plex_libraries" @@ -54,12 +63,20 @@ async def get_libraries( all_libraries.append(f"{plex_server.friendlyName} / {media_section.title}") return all_libraries - if cache := await mass.cache.get(cache_key, checksum=auth_token): + if cache := await mass.cache.get( + cache_key, checksum=auth_token, provider=instance_id or local_server_ip + ): return cast("list[str]", cache) result = await asyncio.to_thread(_get_libraries) # use short expiration for in-memory cache - await mass.cache.set(cache_key, result, checksum=auth_token, expiration=3600) + await mass.cache.set( + cache_key, + result, + checksum=auth_token, + expiration=3600, + provider=instance_id or "default", + ) return result -- 2.34.1