From a2e54a760e17932dbbc2de0dec23906107f2cda9 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sun, 7 Jan 2024 19:46:35 +0100 Subject: [PATCH] fix getattr useage --- InvenTree/common/notifications.py | 4 ++-- InvenTree/plugin/base/integration/APICallMixin.py | 2 +- InvenTree/plugin/models.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/InvenTree/common/notifications.py b/InvenTree/common/notifications.py index e52e2d86ff..c32ee3ec82 100644 --- a/InvenTree/common/notifications.py +++ b/InvenTree/common/notifications.py @@ -336,9 +336,9 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs): # Try with some defaults if not obj_ref_value: - obj_ref_value = getattr(obj, 'pk') + obj_ref_value = getattr(obj, 'pk', None) if not obj_ref_value: - obj_ref_value = getattr(obj, 'id') + obj_ref_value = getattr(obj, 'id', None) if not obj_ref_value: raise KeyError(f"Could not resolve an object reference for '{str(obj)}' with {obj_ref}, pk, id") diff --git a/InvenTree/plugin/base/integration/APICallMixin.py b/InvenTree/plugin/base/integration/APICallMixin.py index 7fa6a43d25..1dcef4dc61 100644 --- a/InvenTree/plugin/base/integration/APICallMixin.py +++ b/InvenTree/plugin/base/integration/APICallMixin.py @@ -93,7 +93,7 @@ class APICallMixin: Check the mixin class docstring for a full example. """ headers = {'Content-Type': 'application/json'} - if getattr(self, 'API_TOKEN_SETTING'): + if getattr(self, 'API_TOKEN_SETTING', None): token = self.get_setting(self.API_TOKEN_SETTING) if token: diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index 44f281cf02..fef716b86a 100644 --- a/InvenTree/plugin/models.py +++ b/InvenTree/plugin/models.py @@ -189,7 +189,7 @@ class PluginSetting(common.models.BaseInvenTreeSetting): plugin = kwargs.pop('plugin', None) if plugin: - mixin_settings = getattr(registry, 'mixins_settings') + mixin_settings = getattr(registry, 'mixins_settings', None) if mixin_settings: kwargs['settings'] = mixin_settings.get(plugin.key, {})