mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 03:30:54 +00:00
Add flake8-logging linting (#5620)
* added flake8-logging to make logging more robust * fixed LOG005 warnings * fixed LOG008 warnings * fixed LOG011 warnings * fixed more LOG011 errors * added ignores for intentional logger.error calls * fixed even more LOG011 errors
This commit is contained in:
@ -227,7 +227,7 @@ class BaseInvenTreeSetting(models.Model):
|
||||
if self.pk is None:
|
||||
return
|
||||
|
||||
logger.debug(f"Saving setting '{ckey}' to cache")
|
||||
logger.debug("Saving setting '%s' to cache", ckey)
|
||||
|
||||
try:
|
||||
cache.set(
|
||||
@ -769,19 +769,19 @@ class BaseInvenTreeSetting(models.Model):
|
||||
try:
|
||||
(app, mdl) = model_name.strip().split('.')
|
||||
except ValueError:
|
||||
logger.error(f"Invalid 'model' parameter for setting {self.key} : '{model_name}'")
|
||||
logger.exception("Invalid 'model' parameter for setting '%s': '%s'", self.key, model_name)
|
||||
return None
|
||||
|
||||
app_models = apps.all_models.get(app, None)
|
||||
|
||||
if app_models is None:
|
||||
logger.error(f"Error retrieving model class '{model_name}' for setting '{self.key}' - no app named '{app}'")
|
||||
logger.error("Error retrieving model class '%s' for setting '%s' - no app named '%s'", model_name, self.key, app)
|
||||
return None
|
||||
|
||||
model = app_models.get(mdl, None)
|
||||
|
||||
if model is None:
|
||||
logger.error(f"Error retrieving model class '{model_name}' for setting '{self.key}' - no model named '{mdl}'")
|
||||
logger.error("Error retrieving model class '%s' for setting '%s' - no model named '%s'", model_name, self.key, mdl)
|
||||
return None
|
||||
|
||||
# Looks like we have found a model!
|
||||
@ -2269,7 +2269,7 @@ class PriceBreak(MetaMixin):
|
||||
try:
|
||||
converted = convert_money(self.price, currency_code)
|
||||
except MissingRate:
|
||||
logger.warning(f"No currency conversion rate available for {self.price_currency} -> {currency_code}")
|
||||
logger.warning("No currency conversion rate available for %s -> %s", self.price_currency, currency_code)
|
||||
return self.price.amount
|
||||
|
||||
return converted.amount
|
||||
|
@ -196,7 +196,7 @@ class MethodStorageClass:
|
||||
filtered_list[ref] = item
|
||||
|
||||
storage.liste = list(filtered_list.values())
|
||||
logger.info(f'Found {len(storage.liste)} notification methods')
|
||||
logger.info('Found %s notification methods', len(storage.liste))
|
||||
|
||||
def get_usersettings(self, user) -> list:
|
||||
"""Returns all user settings for a specific user.
|
||||
@ -339,10 +339,10 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
|
||||
delta = timedelta(days=1)
|
||||
|
||||
if common.models.NotificationEntry.check_recent(category, obj_ref_value, delta):
|
||||
logger.info(f"Notification '{category}' has recently been sent for '{str(obj)}' - SKIPPING")
|
||||
logger.info("Notification '%s' has recently been sent for '%s' - SKIPPING", category, str(obj))
|
||||
return
|
||||
|
||||
logger.info(f"Gathering users for notification '{category}'")
|
||||
logger.info("Gathering users for notification '%s'", category)
|
||||
|
||||
if target_exclude is None:
|
||||
target_exclude = set()
|
||||
@ -376,10 +376,10 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
|
||||
target_users.add(user)
|
||||
# Unhandled type
|
||||
else:
|
||||
logger.error(f"Unknown target passed to trigger_notification method: {target}")
|
||||
logger.error("Unknown target passed to trigger_notification method: %s", target)
|
||||
|
||||
if target_users:
|
||||
logger.info(f"Sending notification '{category}' for '{str(obj)}'")
|
||||
logger.info("Sending notification '%s' for '%s'", category, str(obj))
|
||||
|
||||
# Collect possible methods
|
||||
if delivery_methods is None:
|
||||
@ -388,19 +388,19 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
|
||||
delivery_methods = (delivery_methods - IGNORED_NOTIFICATION_CLS)
|
||||
|
||||
for method in delivery_methods:
|
||||
logger.info(f"Triggering notification method '{method.METHOD_NAME}'")
|
||||
logger.info("Triggering notification method '%s'", method.METHOD_NAME)
|
||||
try:
|
||||
deliver_notification(method, obj, category, target_users, context)
|
||||
except NotImplementedError as error:
|
||||
# Allow any single notification method to fail, without failing the others
|
||||
logger.error(error)
|
||||
logger.error(error) # noqa: LOG005
|
||||
except Exception as error:
|
||||
logger.error(error)
|
||||
logger.error(error) # noqa: LOG005
|
||||
|
||||
# Set delivery flag
|
||||
common.models.NotificationEntry.notify(category, obj_ref_value)
|
||||
else:
|
||||
logger.info(f"No possible users for notification '{category}'")
|
||||
logger.info("No possible users for notification '%s'", category)
|
||||
|
||||
|
||||
def trigger_superuser_notification(plugin: PluginConfig, msg: str):
|
||||
@ -440,7 +440,7 @@ def deliver_notification(cls: NotificationMethod, obj, category: str, targets, c
|
||||
|
||||
if method.targets and len(method.targets) > 0:
|
||||
# Log start
|
||||
logger.info(f"Notify users via '{method.METHOD_NAME}' for notification '{category}' for '{str(obj)}'")
|
||||
logger.info("Notify users via '%s' for notification '%s' for '%s'", method.METHOD_NAME, category, str(obj))
|
||||
|
||||
# Run setup for delivery method
|
||||
method.setup()
|
||||
@ -465,6 +465,6 @@ def deliver_notification(cls: NotificationMethod, obj, category: str, targets, c
|
||||
method.cleanup()
|
||||
|
||||
# Log results
|
||||
logger.info(f"Notified {success_count} users via '{method.METHOD_NAME}' for notification '{category}' for '{str(obj)}' successfully")
|
||||
logger.info("Notified %s users via '%s' for notification '%s' for '%s' successfully", success_count, method.METHOD_NAME, category, str(obj))
|
||||
if not success:
|
||||
logger.info("There were some problems")
|
||||
|
@ -93,7 +93,7 @@ def delete_old_notes_images():
|
||||
# Remove any notes which point to non-existent image files
|
||||
for note in NotesImage.objects.all():
|
||||
if not os.path.exists(note.image.path):
|
||||
logger.info(f"Deleting note {note.image.path} - image file does not exist")
|
||||
logger.info("Deleting note %s - image file does not exist", note.image.path)
|
||||
note.delete()
|
||||
|
||||
note_classes = getModelsWithMixin(InvenTreeNotesMixin)
|
||||
@ -112,7 +112,7 @@ def delete_old_notes_images():
|
||||
break
|
||||
|
||||
if not found:
|
||||
logger.info(f"Deleting note {img} - image file not linked to a note")
|
||||
logger.info("Deleting note %s - image file not linked to a note", img)
|
||||
note.delete()
|
||||
|
||||
# Finally, remove any images in the notes dir which are not linked to a note
|
||||
@ -136,5 +136,5 @@ def delete_old_notes_images():
|
||||
break
|
||||
|
||||
if not found:
|
||||
logger.info(f"Deleting note {image} - image file not linked to a note")
|
||||
logger.info("Deleting note %s - image file not linked to a note", image)
|
||||
os.remove(os.path.join(notes_dir, image))
|
||||
|
Reference in New Issue
Block a user