From 3a786173d9b5998702c2c1a096bcf5f5f0473dda Mon Sep 17 00:00:00 2001 From: Thomas Pollet Date: Sun, 22 Dec 2024 12:43:45 +0100 Subject: [PATCH] add debug logs | fix 'Type' setter --- safrs/base.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/safrs/base.py b/safrs/base.py index 7d06382..8f49263 100755 --- a/safrs/base.py +++ b/safrs/base.py @@ -379,8 +379,10 @@ def __setattr__(self, attr_name, attr_val): if is_jsonapi_attr(attr) and attr.fset is None: # jsonapi_attr.setter not implemented for attr return attr_val - else: - return super().__setattr__(attr_name, attr_val) + if attr_name == "Type" and hasattr(self, "type"): + # check "Type" property for details + attr_name = "type" + return super().__setattr__(attr_name, attr_val) def _s_parse_attr_value(self, attr_name: str, attr_val: any): """ @@ -830,6 +832,7 @@ def get_instance(cls, item=None, failsafe=False): try: instance = cls._s_query.filter_by(**primary_keys).first() except Exception as exc: # pragma: no cover + safrs.log.error(f"Failed to get instance with keys {primary_keys}") raise GenericError(f"get_instance : {exc}") if not instance and not failsafe: @@ -886,7 +889,7 @@ def _s_query(cls_or_self): safrs.log.warning("Invalid SQLA request") except Exception as exc: safrs.log.exception(exc) - safrs.log.error(exc) + safrs.log.error(f"Query failed for {cls_or_self}: {exc}") if _table: result = safrs.DB.session.query(_table) @@ -1298,8 +1301,7 @@ def Type(self, value): Type property setter, see comment in the type property """ if not self.Type == value: - self.Type = value - self.type = value + self.type = value @classmethod def _s_filter(cls, *filter_args, **filter_kwargs):