Try to catch encoding error, fixed CI

This commit is contained in:
eeintech 2021-07-19 15:14:08 -04:00
parent 3ab058e84b
commit c1db4c7b3d
2 changed files with 18 additions and 14 deletions

View File

@ -20,7 +20,6 @@ from djmoney.forms.fields import MoneyField
from djmoney.models.validators import MinMoneyValidator from djmoney.models.validators import MinMoneyValidator
import InvenTree.helpers import InvenTree.helpers
import common.settings
class InvenTreeURLFormField(FormURLField): class InvenTreeURLFormField(FormURLField):
@ -42,9 +41,11 @@ class InvenTreeURLField(models.URLField):
def money_kwargs(): def money_kwargs():
""" returns the database settings for MoneyFields """ """ returns the database settings for MoneyFields """
from common.settings import currency_code_mappings, currency_code_default
kwargs = {} kwargs = {}
kwargs['currency_choices'] = common.settings.currency_code_mappings() kwargs['currency_choices'] = currency_code_mappings()
kwargs['default_currency'] = common.settings.currency_code_default() kwargs['default_currency'] = currency_code_default()
return kwargs return kwargs

View File

@ -53,6 +53,7 @@ class FileManager:
ext = os.path.splitext(file.name)[-1].lower().replace('.', '') ext = os.path.splitext(file.name)[-1].lower().replace('.', '')
try:
if ext in ['csv', 'tsv', ]: if ext in ['csv', 'tsv', ]:
# These file formats need string decoding # These file formats need string decoding
raw_data = file.read().decode('utf-8') raw_data = file.read().decode('utf-8')
@ -64,6 +65,8 @@ class FileManager:
file.seek(0) file.seek(0)
else: else:
raise ValidationError(_(f'Unsupported file format: {ext.upper()}')) raise ValidationError(_(f'Unsupported file format: {ext.upper()}'))
except UnicodeEncodeError:
raise ValidationError(_('Error reading file (invalid encoding)'))
try: try:
cleaned_data = tablib.Dataset().load(raw_data, format=ext) cleaned_data = tablib.Dataset().load(raw_data, format=ext)