fix load race in config
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 16 Aug 2024 16:13:12 +0000 (18:13 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 16 Aug 2024 16:13:12 +0000 (18:13 +0200)
music_assistant/server/controllers/config.py

index fac362e0fb2747d9008380d2e334d3563f34d913..5a24442cd5cc0fe85dadc9d679a5a28d4da53ed8 100644 (file)
@@ -820,11 +820,17 @@ class ConfigController:
         )
         # validate the new config
         config.validate()
-        # try to load the provider first to catch errors before we save it.
-        await self.mass.load_provider_config(config)
-        # the load was a success, store this config
+        # save the config first to prevent issues when the
+        # provider wants to manipulate the config during load
         conf_key = f"{CONF_PROVIDERS}/{config.instance_id}"
         self.set(conf_key, config.to_raw())
+        # try to load the provider
+        try:
+            await self._load_provider_config(config)
+        except Exception:
+            # loading failed, remove config
+            self.remove(conf_key)
+            raise
         return config
 
     async def _load_provider_config(self, config: ProviderConfig) -> None: