mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix: Coerce language app config field to None if empty
This commit is contained in:
parent
1ac298f6ff
commit
b0aeec4c43
@ -76,10 +76,10 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
|
||||
config = ApplicationConfiguration.objects.first()
|
||||
self.assertEqual(config.color_conversion_strategy, ColorConvertChoices.RGB)
|
||||
|
||||
def test_api_update_config_empty_json_field(self):
|
||||
def test_api_update_config_empty_fields(self):
|
||||
"""
|
||||
GIVEN:
|
||||
- API request to update app config with empty string for user_args JSONField
|
||||
- API request to update app config with empty string for user_args JSONField and language field
|
||||
WHEN:
|
||||
- API is called
|
||||
THEN:
|
||||
@ -91,6 +91,7 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
|
||||
json.dumps(
|
||||
{
|
||||
"user_args": "",
|
||||
"language": "",
|
||||
},
|
||||
),
|
||||
content_type="application/json",
|
||||
@ -98,3 +99,4 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
config = ApplicationConfiguration.objects.first()
|
||||
self.assertEqual(config.user_args, None)
|
||||
self.assertEqual(config.language, None)
|
||||
|
@ -125,8 +125,11 @@ class ApplicationConfigurationSerializer(serializers.ModelSerializer):
|
||||
user_args = serializers.JSONField(binary=True, allow_null=True)
|
||||
|
||||
def run_validation(self, data):
|
||||
# Empty strings treated as None to avoid unexpected behavior
|
||||
if "user_args" in data and data["user_args"] == "":
|
||||
data["user_args"] = None
|
||||
if "language" in data and data["language"] == "":
|
||||
data["language"] = None
|
||||
return super().run_validation(data)
|
||||
|
||||
class Meta:
|
||||
|
Loading…
x
Reference in New Issue
Block a user