diff --git a/arkindex/process/serializers/workers.py b/arkindex/process/serializers/workers.py index 5b7604a3cc3b5620345cd4da7ed029362234d5a9..bd2b5dd0dc6dbd8beff5ef267572aecd4e4af06c 100644 --- a/arkindex/process/serializers/workers.py +++ b/arkindex/process/serializers/workers.py @@ -153,7 +153,7 @@ class UserConfigurationFieldType(Enum): USER_CONFIGURATION_FIELD_TYPE_DATA_TYPE = { UserConfigurationFieldType.Int: [serializers.IntegerField(), int], - UserConfigurationFieldType.Float: [serializers.FloatField(), float], + UserConfigurationFieldType.Float: [serializers.FloatField(), (int, float)], UserConfigurationFieldType.String: [serializers.CharField(), str], UserConfigurationFieldType.Enum: [serializers.ChoiceField(choices=[]), None], UserConfigurationFieldType.Boolean: [serializers.BooleanField(), bool], @@ -221,8 +221,15 @@ class UserConfigurationFieldSerializer(serializers.Serializer): data_type, data_class = USER_CONFIGURATION_FIELD_TYPE_DATA_TYPE[field_type] if not isinstance(default_value, data_class): raise ValidationError + # In the case of model fields, the validation error is raised here if the default value is a string but not a UUID data_type.to_internal_value(default_value) + + # The DRF IntegerField forbids parsing a boolean as an int while the FloatField allows it + # We prevent treating booleans as floats here to stay consistent + if field_type == UserConfigurationFieldType.Float and isinstance(default_value, bool): + raise ValidationError + # For lists, check that list elements are of given subtype if field_type == UserConfigurationFieldType.List and not errors.get("subtype"): _, data_subclass = USER_CONFIGURATION_FIELD_TYPE_DATA_TYPE[subtype] diff --git a/arkindex/process/tests/worker_versions/test_create.py b/arkindex/process/tests/worker_versions/test_create.py index 69a144ea836936e25bc7146932d83dfe62750a80..054907a1bd353c7e738ecfdf718511a22914dd2b 100644 --- a/arkindex/process/tests/worker_versions/test_create.py +++ b/arkindex/process/tests/worker_versions/test_create.py @@ -441,6 +441,12 @@ class TestWorkerVersionCreate(FixtureAPITestCase): "required": True, "default": 1, }, + "demo_float": { + "title": "Demo Float", + "type": "float", + "required": True, + "default": 1, + }, "demo_boolean": { "title": "Demo Boolean", "type": "bool",