diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0d3f059..afac6af 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,7 +35,7 @@ repos: ] - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 24.3.0 hooks: - id: black args: ["--config", "pyproject.toml"] diff --git a/pyunicore/client.py b/pyunicore/client.py index 4871ae3..0cd8c2f 100755 --- a/pyunicore/client.py +++ b/pyunicore/client.py @@ -95,13 +95,14 @@ def __init__( self.verify = verify self.use_security_sessions = use_security_sessions self.last_session_id = None - self.preferences = None + self._preferences = None self.timeout = timeout + self.settings_changed = True def _clone(self): """create a copy of this transport""" tr = Transport(self.credential) - tr.preferences = self.preferences + tr._preferences = self._preferences tr.use_security_sessions = self.use_security_sessions tr.last_session_id = self.last_session_id tr.timeout = self.timeout @@ -120,8 +121,8 @@ def _headers(self, kwargs): if self.use_security_sessions and self.last_session_id is not None: headers["X-UNICORE-SecuritySession"] = self.last_session_id - if self.preferences is not None: - headers["X-UNICORE-User-Preferences"] = self.preferences + if self._preferences is not None: + headers["X-UNICORE-User-Preferences"] = self._preferences if "headers" in kwargs: headers.update(kwargs["headers"]) @@ -129,6 +130,16 @@ def _headers(self, kwargs): return headers + @property + def preferences(self): + return self._preferences + + @preferences.setter + def preferences(self, value): + self._preferences = value + self.last_session_id = None + self.settings_changed = True + def check_error(self, res): """checks for error and extracts any error info sent by the server""" if 400 <= res.status_code < 600: @@ -163,6 +174,7 @@ def run_method(self, method, **args): self.check_error(res) if self.use_security_sessions: self.last_session_id = res.headers.get("X-UNICORE-SecuritySession", None) + self.settings_changed = False return res def get(self, to_json=True, **kwargs): @@ -221,8 +233,10 @@ def __init__(self, security, resource_url, cache_time=_DEFAULT_CACHE_TIME): def properties(self): """get resource properties (these are cached for cache_time seconds)""" now = datetime.now() - if self.cache_time <= 0 or ( - timedelta(seconds=self.cache_time) < now - self._last_retrieved + if ( + self.transport.settings_changed + or self.cache_time <= 0 + or (timedelta(seconds=self.cache_time) < now - self._last_retrieved) ): self._last_properties = self.transport.get(url=self.resource_url) self._last_retrieved = now