Fix user_id attribute modification in Component
class
This commit is contained in:
parent
26bc28b0e1
commit
53a1aa57bc
2 changed files with 7 additions and 4 deletions
|
|
@ -28,10 +28,13 @@ class Component:
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
self.cache = TTLCache(maxsize=1024, ttl=60)
|
self.cache = TTLCache(maxsize=1024, ttl=60)
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
setattr(self, key, value)
|
if key == "user_id":
|
||||||
|
setattr(self, "_user_id", value)
|
||||||
|
else:
|
||||||
|
setattr(self, key, value)
|
||||||
|
|
||||||
def __setattr__(self, key, value):
|
def __setattr__(self, key, value):
|
||||||
if key == "user_id" and hasattr(self, key):
|
if key == "_user_id" and hasattr(self, "_user_id"):
|
||||||
warnings.warn("Modification of user_id is not allowed")
|
warnings.warn("Modification of user_id is not allowed")
|
||||||
else:
|
else:
|
||||||
super().__setattr__(key, value)
|
super().__setattr__(key, value)
|
||||||
|
|
|
||||||
|
|
@ -186,13 +186,13 @@ class CustomComponent(Component):
|
||||||
@property
|
@property
|
||||||
def keys(self):
|
def keys(self):
|
||||||
def get_credential(name: str):
|
def get_credential(name: str):
|
||||||
if not self.user_id:
|
if hasattr(self, "_user_id") and not self._user_id:
|
||||||
raise ValueError(f"User id is not set for {self.__class__.__name__}")
|
raise ValueError(f"User id is not set for {self.__class__.__name__}")
|
||||||
credential_service = get_credential_service() # Get service instance
|
credential_service = get_credential_service() # Get service instance
|
||||||
# Retrieve and decrypt the credential by name for the current user
|
# Retrieve and decrypt the credential by name for the current user
|
||||||
db_service = get_db_service()
|
db_service = get_db_service()
|
||||||
with session_getter(db_service) as session:
|
with session_getter(db_service) as session:
|
||||||
return credential_service.get_credential(user_id=self.user_id, name=name, session=session)
|
return credential_service.get_credential(user_id=self._user_id, name=name, session=session)
|
||||||
|
|
||||||
return get_credential
|
return get_credential
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue