]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: Coerce language app config field to None if empty
authorshamoon <4887959+shamoon@users.noreply.github.com>
Wed, 10 Jan 2024 21:21:51 +0000 (13:21 -0800)
committershamoon <4887959+shamoon@users.noreply.github.com>
Wed, 10 Jan 2024 21:21:51 +0000 (13:21 -0800)
src/documents/tests/test_api_app_config.py
src/paperless/serialisers.py

index ed3a4b12f7ef9cfc9652da84c02fc485aa9a20ca..a12d2a69590574c5826d42616d160b6ba397f430 100644 (file)
@@ -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)
index 50407564b22390cb735a28c5b9248da061df537b..fb366f808eadb586ea735f650da8ee06ac5fea8d 100644 (file)
@@ -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: