From 6cbd53f45dbb4003307d70430e96e211d4d23394 Mon Sep 17 00:00:00 2001 From: onefloid <33193059+onefloid@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:39:58 +0200 Subject: [PATCH] Fix: Use lazy initialization for ServerService and MonitoringService to suppress depracation warnings for the majority of users --- TM1py/Services/TM1Service.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/TM1py/Services/TM1Service.py b/TM1py/Services/TM1Service.py index 9f1ce2c3..5a05e450 100644 --- a/TM1py/Services/TM1Service.py +++ b/TM1py/Services/TM1Service.py @@ -87,11 +87,12 @@ def __init__(self, **kwargs): self.audit_logs = AuditLogService(self._tm1_rest) #higher level modules - self.server = ServerService(self._tm1_rest) - self.monitoring = MonitoringService(self._tm1_rest) self.power_bi = PowerBiService(self._tm1_rest) self.loggers = LoggerService(self._tm1_rest) + self._server = None + self._monitoring = None + def logout(self, **kwargs): self._tm1_rest.logout(**kwargs) @@ -103,6 +104,18 @@ def __exit__(self, exception_type, exception_value, traceback): self.logout() except Exception as e: warnings.warn(f"Logout Failed due to Exception: {e}") + + @property + def server(self): + if not self._server: + self._server = ServerService(self._tm1_rest) + return self._server + + @property + def monitoring(self): + if not self._monitoring: + self._monitoring = MonitoringService(self._tm1_rest) + return self._monitoring @property def whoami(self):