def __init__(self, id, message, db_data, settings, descriptions, parametrizer_cls, load_error=False): self.settings = settings try: user_values = json.loads(db_data) if db_data else None except ValueError: user_values = None smart_kit_metrics.counter_load_error(settings.app_name) log(f"%(class_name)s.__init__ User load ValueError %(uid)s with user data {db_data}", params={ log_const.KEY_NAME: log_const.FAILED_DB_INTERACTION, "uid": str(id) }, level="ERROR") load_error = True super(User, self).__init__(id, message, user_values, descriptions, load_error) self.__parametrizer_cls = parametrizer_cls self.do_not_save = False self.initial_db_data = db_data
def load_user(self, db_uid, message): db_data = None load_error = False try: db_data = self.db_adapter.get(db_uid) except (DBAdapterException, ValueError): log("Failed to get user data", params={log_const.KEY_NAME: log_const.FAILED_DB_INTERACTION, log_const.REQUEST_VALUE: str(message.value)}, level="ERROR") load_error = True smart_kit_metrics.counter_load_error(self.app_name) return self.user_cls( message.uid, message=message, db_data=db_data, settings=self.settings, descriptions=self.model.scenario_descriptions, parametrizer_cls=self.parametrizer_cls, load_error=load_error )