uranusjr commented on a change in pull request #17387:
URL: https://github.com/apache/airflow/pull/17387#discussion_r681421325



##########
File path: airflow/providers/hashicorp/_internal_client/vault_client.py
##########
@@ -191,8 +191,21 @@ def __init__(
         self.radius_secret = radius_secret
         self.radius_port = radius_port
 
+    @property
+    def client(self):
+        """
+        Wrapper function to invalidate cache
+
+        :rtype: hvac.Client
+        :return: Vault Client
+
+        """
+        if '_client' in self.__dict__ and not self._client.is_authenticated():
+            del self.__dict__['_client']
+        return self._client

Review comment:
       ```suggestion
           client = self._client
           # Invalidate so we can provide auth to get an authenticated client 
later.
           if not client.is_authenticated():
               del self.__dict__['_client']        
           return client
   ```
   
   I wonder if this is easier to undersstand.
   
   Also, modifying `__dict__` to invalidate the cached property feels a bit 
hacky to me (although `cached_property` is well-documented to use `__dict__` so 
it’s probably OK).
   
   Maybe it’s better to do something like this?
   
   ```python
   @functools.lru_cache()
   def _create_client(self) -> hvac.Client:
       ...
   
   @property
   def client(self) -> hvac.Client:
       client = self._create_client()
       if not client.is_authenticated():
           self._create_client.cache_clear()
       return client
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to