2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-16 00:50:56 +00:00

Ensure empty string values are converted to None

This commit is contained in:
Oliver Walters
2025-12-02 05:39:04 +00:00
parent 06bc811c16
commit 9da6e15df4
4 changed files with 23 additions and 6 deletions

View File

@@ -733,6 +733,10 @@ class ParameterTemplateSerializer(
allow_null=True,
)
def validate_model_type(self, model_type):
"""Convert an empty string to None for the model_type field."""
return model_type or None
@register_importer()
class ParameterSerializer(

View File

@@ -121,6 +121,19 @@ class ParameterAPITests(InvenTreeAPITestCase):
self.assertEqual(common.models.ParameterTemplate.objects.count(), N)
self.assertFalse(common.models.ParameterTemplate.objects.filter(pk=pk).exists())
# Let's create a template which does not specify a model_type
data = {
'name': 'Universal Parameter',
'units': '',
'description': 'A parameter template for all models',
'enabled': False,
}
response = self.post(url, data, expected_code=201)
self.assertIsNone(response.data['model_type'])
self.assertFalse(response.data['enabled'])
def test_template_filters(self):
"""Tests for API filters against ParameterTemplate endpoint."""
from company.models import Company

View File

@@ -3330,11 +3330,11 @@ class PartTestTemplateTest(PartAPITestBase):
self.assertIn('Choices must be unique', str(response.data['choices']))
class PartParameterTests(PartAPITestBase):
"""Unit test for PartParameter API endpoints."""
class ParameterTests(PartAPITestBase):
"""Unit test for Parameter API endpoints."""
def test_export_data(self):
"""Test data export functionality for PartParameter objects."""
"""Test data export functionality for Parameter objects."""
url = reverse('api-parameter-list')
response = self.options(

View File

@@ -287,8 +287,8 @@ class ParameterTests(TestCase):
self.assertAlmostEqual(param.data_numeric, expected, places=2)
class PartParameterTest(InvenTreeAPITestCase):
"""Tests for the ParParameter API."""
class ParameterTest(InvenTreeAPITestCase):
"""Tests for the Parameter API."""
superuser = True
@@ -496,7 +496,7 @@ class PartParameterTest(InvenTreeAPITestCase):
self.assertEqual(actual, expected)
class PartParameterFilterTest(InvenTreeAPITestCase):
class ParameterFilterTest(InvenTreeAPITestCase):
"""Unit tests for filtering parts by parameter values."""
superuser = True