2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Various SAST fixes (#8718)

* fix type

* fix typing

* fix python:S5713

* fix python:S1066

* fix python:S3516

* fix python:S5727

* fix python:S5886
This commit is contained in:
Matthias Mair 2024-12-18 21:31:33 +01:00 committed by GitHub
parent 1493bbaac6
commit 1c9f56011c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 28 additions and 18 deletions

View File

@ -278,7 +278,7 @@ class ScheduledTask:
func: Callable
interval: str
minutes: int = None
minutes: Optional[int] = None
MINUTES = 'I'
HOURLY = 'H'

View File

@ -113,7 +113,7 @@ def validate_overage(value):
raise ValidationError(_('Overage value must not be negative'))
# Looks like a number
return True
return
except (ValueError, InvalidOperation):
pass
@ -130,7 +130,7 @@ def validate_overage(value):
elif f > 100:
raise ValidationError(_('Overage must not exceed 100%'))
return True
return
except ValueError:
pass

View File

@ -30,7 +30,7 @@ try:
main_repo = Repo(pathlib.Path(__file__).parent.parent.parent.parent.parent)
main_commit = main_repo[main_repo.head()]
except (ImportError, ModuleNotFoundError):
except ImportError:
logger.warning(
'Warning: Dulwich module not found, git information will not be available.'
)

View File

@ -3,6 +3,7 @@
import decimal
import logging
import math
from typing import Optional
from django.core.cache import cache
from django.core.exceptions import ValidationError
@ -143,7 +144,7 @@ def validate_currency_codes(value):
return list(valid_currencies)
def currency_exchange_plugins() -> list:
def currency_exchange_plugins() -> Optional[list]:
"""Return a list of plugin choices which can be used for currency exchange."""
try:
from plugin import registry

View File

@ -3,6 +3,7 @@
import logging
from dataclasses import dataclass
from datetime import timedelta
from typing import Optional
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
@ -315,7 +316,7 @@ class NotificationBody:
name: str
slug: str
message: str
template: str = None
template: Optional[str] = None
class InvenTreeNotificationBodies:

View File

@ -50,7 +50,9 @@ def update_news_feed():
return
# News feed isn't defined, no need to continue
if not settings.INVENTREE_NEWS_URL or type(settings.INVENTREE_NEWS_URL) != str:
if not settings.INVENTREE_NEWS_URL or not isinstance(
settings.INVENTREE_NEWS_URL, str
):
return
# Fetch and parse feed

View File

@ -1046,11 +1046,14 @@ class SupplierPriceBreak(common.models.PriceBreak):
def after_save_supplier_price(sender, instance, created, **kwargs):
"""Callback function when a SupplierPriceBreak is created or updated."""
if (
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
and not InvenTree.ready.isImportingData()
(
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
and not InvenTree.ready.isImportingData()
)
and instance.part
and instance.part.part
):
if instance.part and instance.part.part:
instance.part.part.schedule_pricing_update(create=True)
instance.part.part.schedule_pricing_update(create=True)
@receiver(
@ -1061,8 +1064,11 @@ def after_save_supplier_price(sender, instance, created, **kwargs):
def after_delete_supplier_price(sender, instance, **kwargs):
"""Callback function when a SupplierPriceBreak is deleted."""
if (
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
and not InvenTree.ready.isImportingData()
(
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
and not InvenTree.ready.isImportingData()
)
and instance.part
and instance.part.part
):
if instance.part and instance.part.part:
instance.part.part.schedule_pricing_update(create=False)
instance.part.part.schedule_pricing_update(create=False)

View File

@ -36,7 +36,7 @@ def load_data_file(data_file, file_format=None):
try:
data = file_object.read()
except (OSError, FileNotFoundError):
except OSError:
raise ValidationError(_('Failed to open data file'))
# Excel formats expect binary data

View File

@ -57,7 +57,7 @@ class BarcodeView(CreateAPIView):
return
# Ensure that the response data is stringified first, otherwise cannot be JSON encoded
if type(response) is dict:
if isinstance(response, dict):
response = {key: str(value) for key, value in response.items()}
elif response is None:
pass
@ -65,7 +65,7 @@ class BarcodeView(CreateAPIView):
response = str(response)
# Ensure that the context data is stringified first, otherwise cannot be JSON encoded
if type(context) is dict:
if isinstance(context, dict):
context = {key: str(value) for key, value in context.items()}
elif context is None:
pass