mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26: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:
parent
1493bbaac6
commit
1c9f56011c
@ -278,7 +278,7 @@ class ScheduledTask:
|
|||||||
|
|
||||||
func: Callable
|
func: Callable
|
||||||
interval: str
|
interval: str
|
||||||
minutes: int = None
|
minutes: Optional[int] = None
|
||||||
|
|
||||||
MINUTES = 'I'
|
MINUTES = 'I'
|
||||||
HOURLY = 'H'
|
HOURLY = 'H'
|
||||||
|
@ -113,7 +113,7 @@ def validate_overage(value):
|
|||||||
raise ValidationError(_('Overage value must not be negative'))
|
raise ValidationError(_('Overage value must not be negative'))
|
||||||
|
|
||||||
# Looks like a number
|
# Looks like a number
|
||||||
return True
|
return
|
||||||
except (ValueError, InvalidOperation):
|
except (ValueError, InvalidOperation):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ def validate_overage(value):
|
|||||||
elif f > 100:
|
elif f > 100:
|
||||||
raise ValidationError(_('Overage must not exceed 100%'))
|
raise ValidationError(_('Overage must not exceed 100%'))
|
||||||
|
|
||||||
return True
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ try:
|
|||||||
|
|
||||||
main_repo = Repo(pathlib.Path(__file__).parent.parent.parent.parent.parent)
|
main_repo = Repo(pathlib.Path(__file__).parent.parent.parent.parent.parent)
|
||||||
main_commit = main_repo[main_repo.head()]
|
main_commit = main_repo[main_repo.head()]
|
||||||
except (ImportError, ModuleNotFoundError):
|
except ImportError:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
'Warning: Dulwich module not found, git information will not be available.'
|
'Warning: Dulwich module not found, git information will not be available.'
|
||||||
)
|
)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import decimal
|
import decimal
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@ -143,7 +144,7 @@ def validate_currency_codes(value):
|
|||||||
return list(valid_currencies)
|
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."""
|
"""Return a list of plugin choices which can be used for currency exchange."""
|
||||||
try:
|
try:
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
@ -315,7 +316,7 @@ class NotificationBody:
|
|||||||
name: str
|
name: str
|
||||||
slug: str
|
slug: str
|
||||||
message: str
|
message: str
|
||||||
template: str = None
|
template: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeNotificationBodies:
|
class InvenTreeNotificationBodies:
|
||||||
|
@ -50,7 +50,9 @@ def update_news_feed():
|
|||||||
return
|
return
|
||||||
|
|
||||||
# News feed isn't defined, no need to continue
|
# 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
|
return
|
||||||
|
|
||||||
# Fetch and parse feed
|
# Fetch and parse feed
|
||||||
|
@ -1046,10 +1046,13 @@ class SupplierPriceBreak(common.models.PriceBreak):
|
|||||||
def after_save_supplier_price(sender, instance, created, **kwargs):
|
def after_save_supplier_price(sender, instance, created, **kwargs):
|
||||||
"""Callback function when a SupplierPriceBreak is created or updated."""
|
"""Callback function when a SupplierPriceBreak is created or updated."""
|
||||||
if (
|
if (
|
||||||
|
(
|
||||||
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
||||||
and not InvenTree.ready.isImportingData()
|
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)
|
||||||
|
|
||||||
|
|
||||||
@ -1061,8 +1064,11 @@ def after_save_supplier_price(sender, instance, created, **kwargs):
|
|||||||
def after_delete_supplier_price(sender, instance, **kwargs):
|
def after_delete_supplier_price(sender, instance, **kwargs):
|
||||||
"""Callback function when a SupplierPriceBreak is deleted."""
|
"""Callback function when a SupplierPriceBreak is deleted."""
|
||||||
if (
|
if (
|
||||||
|
(
|
||||||
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
|
||||||
and not InvenTree.ready.isImportingData()
|
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)
|
||||||
|
@ -36,7 +36,7 @@ def load_data_file(data_file, file_format=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = file_object.read()
|
data = file_object.read()
|
||||||
except (OSError, FileNotFoundError):
|
except OSError:
|
||||||
raise ValidationError(_('Failed to open data file'))
|
raise ValidationError(_('Failed to open data file'))
|
||||||
|
|
||||||
# Excel formats expect binary data
|
# Excel formats expect binary data
|
||||||
|
@ -57,7 +57,7 @@ class BarcodeView(CreateAPIView):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Ensure that the response data is stringified first, otherwise cannot be JSON encoded
|
# 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()}
|
response = {key: str(value) for key, value in response.items()}
|
||||||
elif response is None:
|
elif response is None:
|
||||||
pass
|
pass
|
||||||
@ -65,7 +65,7 @@ class BarcodeView(CreateAPIView):
|
|||||||
response = str(response)
|
response = str(response)
|
||||||
|
|
||||||
# Ensure that the context data is stringified first, otherwise cannot be JSON encoded
|
# 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()}
|
context = {key: str(value) for key, value in context.items()}
|
||||||
elif context is None:
|
elif context is None:
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user