We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] Server Error 500 when granting History All
### Description

I just tried to create a user group, granting History All to that group. Pressing save in the dialog results in an Internal Server error.

I am running a slightly customized ARM64 image, which includes zxing-cpp. I don't believe this is related to the issue.

### Steps to reproduce

1. Go To "Users & Groups"
2. Create a new group
3. Grant "History All" to that Group
4. Press Save

### Webserver logs

```bash
[2024-05-07 13:25:27,270] [ERROR] [django.request] Internal Server Error: /api/groups/34/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 468, in __call__
    ret = await asyncio.shield(exec_coro)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 522, in thread_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/mixins.py", line 67, in update
    serializer.is_valid(raise_exception=True)
  File "/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py", line 227, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py", line 426, in run_validation
    value = self.to_internal_value(data)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py", line 483, in to_internal_value
    validated_value = field.run_validation(primitive_value)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/fields.py", line 547, in run_validation
    value = self.to_internal_value(data)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/relations.py", line 528, in to_internal_value
    return [
           ^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/relations.py", line 529, in <listcomp>
    self.child_relation.to_internal_value(item)
  File "/usr/local/lib/python3.11/site-packages/rest_framework/relations.py", line 462, in to_internal_value
    return queryset.get(**{self.slug_field: data})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 640, in get
    raise self.model.MultipleObjectsReturned(
django.contrib.auth.models.Permission.MultipleObjectsReturned: get() returned more than one Permission -- it returned 2!
[2024-05-07 13:25:27,425] [ERROR] [django.request] Internal Server Error: /api/groups/34/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = await get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
    response = await wrapped_callback(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 468, in __call__
    ret = await asyncio.shield(exec_coro)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 522, in thread_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/mixins.py", line 67, in update
    serializer.is_valid(raise_exception=True)
  File "/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py", line 227, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py", line 426, in run_validation
    value = self.to_internal_value(data)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py", line 483, in to_internal_value
    validated_value = field.run_validation(primitive_value)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/fields.py", line 547, in run_validation
    value = self.to_internal_value(data)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/relations.py", line 528, in to_internal_value
    return [
           ^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/relations.py", line 529, in <listcomp>
    self.child_relation.to_internal_value(item)
  File "/usr/local/lib/python3.11/site-packages/rest_framework/relations.py", line 462, in to_internal_value
    return queryset.get(**{self.slug_field: data})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 640, in get
    raise self.model.MultipleObjectsReturned(
django.contrib.auth.models.Permission.MultipleObjectsReturned: get() returned more than one Permission -- it returned 2!
```


### Browser logs

_No response_

### Paperless-ngx version

2.8.1

### Host OS

Kubernetes

### Installation method

Other (please describe above)

### Browser

Arc

### Configuration changes

_No response_

### Other

_No response_

### Please confirm the following

- [X] I believe this issue is a bug that affects all users of Paperless-ngx, not something specific to my installation.
- [X] I have already searched for relevant existing issues and discussions before opening this report.
- [X] I have updated the title field above with a concise description.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/paperless/serialisers.py`
Content:
```
1 import logging
2 
3 from allauth.socialaccount.models import SocialAccount
4 from django.contrib.auth.models import Group
5 from django.contrib.auth.models import Permission
6 from django.contrib.auth.models import User
7 from rest_framework import serializers
8 
9 from paperless.models import ApplicationConfiguration
10 
11 logger = logging.getLogger("paperless.settings")
12 
13 
14 class ObfuscatedUserPasswordField(serializers.Field):
15     """
16     Sends *** string instead of password in the clear
17     """
18 
19     def to_representation(self, value):
20         return "**********" if len(value) > 0 else ""
21 
22     def to_internal_value(self, data):
23         return data
24 
25 
26 class UserSerializer(serializers.ModelSerializer):
27     password = ObfuscatedUserPasswordField(required=False)
28     user_permissions = serializers.SlugRelatedField(
29         many=True,
30         queryset=Permission.objects.exclude(content_type__app_label="admin"),
31         slug_field="codename",
32         required=False,
33     )
34     inherited_permissions = serializers.SerializerMethodField()
35 
36     class Meta:
37         model = User
38         fields = (
39             "id",
40             "username",
41             "email",
42             "password",
43             "first_name",
44             "last_name",
45             "date_joined",
46             "is_staff",
47             "is_active",
48             "is_superuser",
49             "groups",
50             "user_permissions",
51             "inherited_permissions",
52         )
53 
54     def get_inherited_permissions(self, obj):
55         return obj.get_group_permissions()
56 
57     def update(self, instance, validated_data):
58         if "password" in validated_data:
59             if len(validated_data.get("password").replace("*", "")) > 0:
60                 instance.set_password(validated_data.get("password"))
61                 instance.save()
62             validated_data.pop("password")
63         super().update(instance, validated_data)
64         return instance
65 
66     def create(self, validated_data):
67         groups = None
68         if "groups" in validated_data:
69             groups = validated_data.pop("groups")
70         user_permissions = None
71         if "user_permissions" in validated_data:
72             user_permissions = validated_data.pop("user_permissions")
73         password = None
74         if (
75             "password" in validated_data
76             and len(validated_data.get("password").replace("*", "")) > 0
77         ):
78             password = validated_data.pop("password")
79         user = User.objects.create(**validated_data)
80         # set groups
81         if groups:
82             user.groups.set(groups)
83         # set permissions
84         if user_permissions:
85             user.user_permissions.set(user_permissions)
86         # set password
87         if password:
88             user.set_password(password)
89         user.save()
90         return user
91 
92 
93 class GroupSerializer(serializers.ModelSerializer):
94     permissions = serializers.SlugRelatedField(
95         many=True,
96         queryset=Permission.objects.all(),
97         slug_field="codename",
98     )
99 
100     class Meta:
101         model = Group
102         fields = (
103             "id",
104             "name",
105             "permissions",
106         )
107 
108 
109 class SocialAccountSerializer(serializers.ModelSerializer):
110     name = serializers.SerializerMethodField()
111 
112     class Meta:
113         model = SocialAccount
114         fields = (
115             "id",
116             "provider",
117             "name",
118         )
119 
120     def get_name(self, obj):
121         return obj.get_provider_account().to_str()
122 
123 
124 class ProfileSerializer(serializers.ModelSerializer):
125     email = serializers.EmailField(allow_null=False)
126     password = ObfuscatedUserPasswordField(required=False, allow_null=False)
127     auth_token = serializers.SlugRelatedField(read_only=True, slug_field="key")
128     social_accounts = SocialAccountSerializer(
129         many=True,
130         read_only=True,
131         source="socialaccount_set",
132     )
133 
134     class Meta:
135         model = User
136         fields = (
137             "email",
138             "password",
139             "first_name",
140             "last_name",
141             "auth_token",
142             "social_accounts",
143             "has_usable_password",
144         )
145 
146 
147 class ApplicationConfigurationSerializer(serializers.ModelSerializer):
148     user_args = serializers.JSONField(binary=True, allow_null=True)
149 
150     def run_validation(self, data):
151         # Empty strings treated as None to avoid unexpected behavior
152         if "user_args" in data and data["user_args"] == "":
153             data["user_args"] = None
154         if "language" in data and data["language"] == "":
155             data["language"] = None
156         return super().run_validation(data)
157 
158     def update(self, instance, validated_data):
159         if instance.app_logo and "app_logo" in validated_data:
160             instance.app_logo.delete()
161         return super().update(instance, validated_data)
162 
163     class Meta:
164         model = ApplicationConfiguration
165         fields = "__all__"
166
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/paperless/serialisers.py b/src/paperless/serialisers.py
--- a/src/paperless/serialisers.py
+++ b/src/paperless/serialisers.py
@@ -93,7 +93,7 @@
 class GroupSerializer(serializers.ModelSerializer):
     permissions = serializers.SlugRelatedField(
         many=True,
-        queryset=Permission.objects.all(),
+        queryset=Permission.objects.exclude(content_type__app_label="admin"),
         slug_field="codename",
     )

{"golden_diff": "diff --git a/src/paperless/serialisers.py b/src/paperless/serialisers.py\n--- a/src/paperless/serialisers.py\n+++ b/src/paperless/serialisers.py\n@@ -93,7 +93,7 @@\n class GroupSerializer(serializers.ModelSerializer):\n     permissions = serializers.SlugRelatedField(\n         many=True,\n-        queryset=Permission.objects.all(),\n+        queryset=Permission.objects.exclude(content_type__app_label=\"admin\"),\n         slug_field=\"codename\",\n     )\n", "issue": "[BUG] Server Error 500 when granting History All\n### Description\n\nI just tried to create a user group, granting History All to that group. Pressing save in the dialog results in an Internal Server error.\r\n\r\nI am running a slightly customized ARM64 image, which includes zxing-cpp. I don't believe this is related to the issue.\n\n### Steps to reproduce\n\n1. Go To \"Users & Groups\"\r\n2. Create a new group\r\n3. Grant \"History All\" to that Group\r\n4. Press Save\n\n### Webserver logs\n\n```bash\n[2024-05-07 13:25:27,270] [ERROR] [django.request] Internal Server Error: /api/groups/34/\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 518, in thread_handler\r\n    raise exc_info[1]\r\n  File \"/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py\", line 42, in inner\r\n    response = await get_response(request)\r\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 518, in thread_handler\r\n    raise exc_info[1]\r\n  File \"/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py\", line 253, in _get_response_async\r\n    response = await wrapped_callback(\r\n               ^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 468, in __call__\r\n    ret = await asyncio.shield(exec_coro)\r\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/current_thread_executor.py\", line 40, in run\r\n    result = self.fn(*self.args, **self.kwargs)\r\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 522, in thread_handler\r\n    return func(*args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/django/views/decorators/csrf.py\", line 56, in wrapper_view\r\n    return view_func(*args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/viewsets.py\", line 125, in view\r\n    return self.dispatch(request, *args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 509, in dispatch\r\n    response = self.handle_exception(exc)\r\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 469, in handle_exception\r\n    self.raise_uncaught_exception(exc)\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 480, in raise_uncaught_exception\r\n    raise exc\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 506, in dispatch\r\n    response = handler(request, *args, **kwargs)\r\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/mixins.py\", line 67, in update\r\n    serializer.is_valid(raise_exception=True)\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py\", line 227, in is_valid\r\n    self._validated_data = self.run_validation(self.initial_data)\r\n                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py\", line 426, in run_validation\r\n    value = self.to_internal_value(data)\r\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py\", line 483, in to_internal_value\r\n    validated_value = field.run_validation(primitive_value)\r\n                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/fields.py\", line 547, in run_validation\r\n    value = self.to_internal_value(data)\r\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/relations.py\", line 528, in to_internal_value\r\n    return [\r\n           ^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/relations.py\", line 529, in <listcomp>\r\n    self.child_relation.to_internal_value(item)\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/relations.py\", line 462, in to_internal_value\r\n    return queryset.get(**{self.slug_field: data})\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/django/db/models/query.py\", line 640, in get\r\n    raise self.model.MultipleObjectsReturned(\r\ndjango.contrib.auth.models.Permission.MultipleObjectsReturned: get() returned more than one Permission -- it returned 2!\r\n[2024-05-07 13:25:27,425] [ERROR] [django.request] Internal Server Error: /api/groups/34/\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 518, in thread_handler\r\n    raise exc_info[1]\r\n  File \"/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py\", line 42, in inner\r\n    response = await get_response(request)\r\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 518, in thread_handler\r\n    raise exc_info[1]\r\n  File \"/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py\", line 253, in _get_response_async\r\n    response = await wrapped_callback(\r\n               ^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 468, in __call__\r\n    ret = await asyncio.shield(exec_coro)\r\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/current_thread_executor.py\", line 40, in run\r\n    result = self.fn(*self.args, **self.kwargs)\r\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/asgiref/sync.py\", line 522, in thread_handler\r\n    return func(*args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/django/views/decorators/csrf.py\", line 56, in wrapper_view\r\n    return view_func(*args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/viewsets.py\", line 125, in view\r\n    return self.dispatch(request, *args, **kwargs)\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 509, in dispatch\r\n    response = self.handle_exception(exc)\r\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 469, in handle_exception\r\n    self.raise_uncaught_exception(exc)\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 480, in raise_uncaught_exception\r\n    raise exc\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/views.py\", line 506, in dispatch\r\n    response = handler(request, *args, **kwargs)\r\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/mixins.py\", line 67, in update\r\n    serializer.is_valid(raise_exception=True)\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py\", line 227, in is_valid\r\n    self._validated_data = self.run_validation(self.initial_data)\r\n                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py\", line 426, in run_validation\r\n    value = self.to_internal_value(data)\r\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py\", line 483, in to_internal_value\r\n    validated_value = field.run_validation(primitive_value)\r\n                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/fields.py\", line 547, in run_validation\r\n    value = self.to_internal_value(data)\r\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/relations.py\", line 528, in to_internal_value\r\n    return [\r\n           ^\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/relations.py\", line 529, in <listcomp>\r\n    self.child_relation.to_internal_value(item)\r\n  File \"/usr/local/lib/python3.11/site-packages/rest_framework/relations.py\", line 462, in to_internal_value\r\n    return queryset.get(**{self.slug_field: data})\r\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"/usr/local/lib/python3.11/site-packages/django/db/models/query.py\", line 640, in get\r\n    raise self.model.MultipleObjectsReturned(\r\ndjango.contrib.auth.models.Permission.MultipleObjectsReturned: get() returned more than one Permission -- it returned 2!\n```\n\n\n### Browser logs\n\n_No response_\n\n### Paperless-ngx version\n\n2.8.1\n\n### Host OS\n\nKubernetes\n\n### Installation method\n\nOther (please describe above)\n\n### Browser\n\nArc\n\n### Configuration changes\n\n_No response_\n\n### Other\n\n_No response_\n\n### Please confirm the following\n\n- [X] I believe this issue is a bug that affects all users of Paperless-ngx, not something specific to my installation.\n- [X] I have already searched for relevant existing issues and discussions before opening this report.\n- [X] I have updated the title field above with a concise description.\n", "before_files": [{"content": "import logging\n\nfrom allauth.socialaccount.models import SocialAccount\nfrom django.contrib.auth.models import Group\nfrom django.contrib.auth.models import Permission\nfrom django.contrib.auth.models import User\nfrom rest_framework import serializers\n\nfrom paperless.models import ApplicationConfiguration\n\nlogger = logging.getLogger(\"paperless.settings\")\n\n\nclass ObfuscatedUserPasswordField(serializers.Field):\n    \"\"\"\n    Sends *** string instead of password in the clear\n    \"\"\"\n\n    def to_representation(self, value):\n        return \"**********\" if len(value) > 0 else \"\"\n\n    def to_internal_value(self, data):\n        return data\n\n\nclass UserSerializer(serializers.ModelSerializer):\n    password = ObfuscatedUserPasswordField(required=False)\n    user_permissions = serializers.SlugRelatedField(\n        many=True,\n        queryset=Permission.objects.exclude(content_type__app_label=\"admin\"),\n        slug_field=\"codename\",\n        required=False,\n    )\n    inherited_permissions = serializers.SerializerMethodField()\n\n    class Meta:\n        model = User\n        fields = (\n            \"id\",\n            \"username\",\n            \"email\",\n            \"password\",\n            \"first_name\",\n            \"last_name\",\n            \"date_joined\",\n            \"is_staff\",\n            \"is_active\",\n            \"is_superuser\",\n            \"groups\",\n            \"user_permissions\",\n            \"inherited_permissions\",\n        )\n\n    def get_inherited_permissions(self, obj):\n        return obj.get_group_permissions()\n\n    def update(self, instance, validated_data):\n        if \"password\" in validated_data:\n            if len(validated_data.get(\"password\").replace(\"*\", \"\")) > 0:\n                instance.set_password(validated_data.get(\"password\"))\n                instance.save()\n            validated_data.pop(\"password\")\n        super().update(instance, validated_data)\n        return instance\n\n    def create(self, validated_data):\n        groups = None\n        if \"groups\" in validated_data:\n            groups = validated_data.pop(\"groups\")\n        user_permissions = None\n        if \"user_permissions\" in validated_data:\n            user_permissions = validated_data.pop(\"user_permissions\")\n        password = None\n        if (\n            \"password\" in validated_data\n            and len(validated_data.get(\"password\").replace(\"*\", \"\")) > 0\n        ):\n            password = validated_data.pop(\"password\")\n        user = User.objects.create(**validated_data)\n        # set groups\n        if groups:\n            user.groups.set(groups)\n        # set permissions\n        if user_permissions:\n            user.user_permissions.set(user_permissions)\n        # set password\n        if password:\n            user.set_password(password)\n        user.save()\n        return user\n\n\nclass GroupSerializer(serializers.ModelSerializer):\n    permissions = serializers.SlugRelatedField(\n        many=True,\n        queryset=Permission.objects.all(),\n        slug_field=\"codename\",\n    )\n\n    class Meta:\n        model = Group\n        fields = (\n            \"id\",\n            \"name\",\n            \"permissions\",\n        )\n\n\nclass SocialAccountSerializer(serializers.ModelSerializer):\n    name = serializers.SerializerMethodField()\n\n    class Meta:\n        model = SocialAccount\n        fields = (\n            \"id\",\n            \"provider\",\n            \"name\",\n        )\n\n    def get_name(self, obj):\n        return obj.get_provider_account().to_str()\n\n\nclass ProfileSerializer(serializers.ModelSerializer):\n    email = serializers.EmailField(allow_null=False)\n    password = ObfuscatedUserPasswordField(required=False, allow_null=False)\n    auth_token = serializers.SlugRelatedField(read_only=True, slug_field=\"key\")\n    social_accounts = SocialAccountSerializer(\n        many=True,\n        read_only=True,\n        source=\"socialaccount_set\",\n    )\n\n    class Meta:\n        model = User\n        fields = (\n            \"email\",\n            \"password\",\n            \"first_name\",\n            \"last_name\",\n            \"auth_token\",\n            \"social_accounts\",\n            \"has_usable_password\",\n        )\n\n\nclass ApplicationConfigurationSerializer(serializers.ModelSerializer):\n    user_args = serializers.JSONField(binary=True, allow_null=True)\n\n    def run_validation(self, data):\n        # Empty strings treated as None to avoid unexpected behavior\n        if \"user_args\" in data and data[\"user_args\"] == \"\":\n            data[\"user_args\"] = None\n        if \"language\" in data and data[\"language\"] == \"\":\n            data[\"language\"] = None\n        return super().run_validation(data)\n\n    def update(self, instance, validated_data):\n        if instance.app_logo and \"app_logo\" in validated_data:\n            instance.app_logo.delete()\n        return super().update(instance, validated_data)\n\n    class Meta:\n        model = ApplicationConfiguration\n        fields = \"__all__\"\n", "path": "src/paperless/serialisers.py"}], "after_files": [{"content": "import logging\n\nfrom allauth.socialaccount.models import SocialAccount\nfrom django.contrib.auth.models import Group\nfrom django.contrib.auth.models import Permission\nfrom django.contrib.auth.models import User\nfrom rest_framework import serializers\n\nfrom paperless.models import ApplicationConfiguration\n\nlogger = logging.getLogger(\"paperless.settings\")\n\n\nclass ObfuscatedUserPasswordField(serializers.Field):\n    \"\"\"\n    Sends *** string instead of password in the clear\n    \"\"\"\n\n    def to_representation(self, value):\n        return \"**********\" if len(value) > 0 else \"\"\n\n    def to_internal_value(self, data):\n        return data\n\n\nclass UserSerializer(serializers.ModelSerializer):\n    password = ObfuscatedUserPasswordField(required=False)\n    user_permissions = serializers.SlugRelatedField(\n        many=True,\n        queryset=Permission.objects.exclude(content_type__app_label=\"admin\"),\n        slug_field=\"codename\",\n        required=False,\n    )\n    inherited_permissions = serializers.SerializerMethodField()\n\n    class Meta:\n        model = User\n        fields = (\n            \"id\",\n            \"username\",\n            \"email\",\n            \"password\",\n            \"first_name\",\n            \"last_name\",\n            \"date_joined\",\n            \"is_staff\",\n            \"is_active\",\n            \"is_superuser\",\n            \"groups\",\n            \"user_permissions\",\n            \"inherited_permissions\",\n        )\n\n    def get_inherited_permissions(self, obj):\n        return obj.get_group_permissions()\n\n    def update(self, instance, validated_data):\n        if \"password\" in validated_data:\n            if len(validated_data.get(\"password\").replace(\"*\", \"\")) > 0:\n                instance.set_password(validated_data.get(\"password\"))\n                instance.save()\n            validated_data.pop(\"password\")\n        super().update(instance, validated_data)\n        return instance\n\n    def create(self, validated_data):\n        groups = None\n        if \"groups\" in validated_data:\n            groups = validated_data.pop(\"groups\")\n        user_permissions = None\n        if \"user_permissions\" in validated_data:\n            user_permissions = validated_data.pop(\"user_permissions\")\n        password = None\n        if (\n            \"password\" in validated_data\n            and len(validated_data.get(\"password\").replace(\"*\", \"\")) > 0\n        ):\n            password = validated_data.pop(\"password\")\n        user = User.objects.create(**validated_data)\n        # set groups\n        if groups:\n            user.groups.set(groups)\n        # set permissions\n        if user_permissions:\n            user.user_permissions.set(user_permissions)\n        # set password\n        if password:\n            user.set_password(password)\n        user.save()\n        return user\n\n\nclass GroupSerializer(serializers.ModelSerializer):\n    permissions = serializers.SlugRelatedField(\n        many=True,\n        queryset=Permission.objects.exclude(content_type__app_label=\"admin\"),\n        slug_field=\"codename\",\n    )\n\n    class Meta:\n        model = Group\n        fields = (\n            \"id\",\n            \"name\",\n            \"permissions\",\n        )\n\n\nclass SocialAccountSerializer(serializers.ModelSerializer):\n    name = serializers.SerializerMethodField()\n\n    class Meta:\n        model = SocialAccount\n        fields = (\n            \"id\",\n            \"provider\",\n            \"name\",\n        )\n\n    def get_name(self, obj):\n        return obj.get_provider_account().to_str()\n\n\nclass ProfileSerializer(serializers.ModelSerializer):\n    email = serializers.EmailField(allow_null=False)\n    password = ObfuscatedUserPasswordField(required=False, allow_null=False)\n    auth_token = serializers.SlugRelatedField(read_only=True, slug_field=\"key\")\n    social_accounts = SocialAccountSerializer(\n        many=True,\n        read_only=True,\n        source=\"socialaccount_set\",\n    )\n\n    class Meta:\n        model = User\n        fields = (\n            \"email\",\n            \"password\",\n            \"first_name\",\n            \"last_name\",\n            \"auth_token\",\n            \"social_accounts\",\n            \"has_usable_password\",\n        )\n\n\nclass ApplicationConfigurationSerializer(serializers.ModelSerializer):\n    user_args = serializers.JSONField(binary=True, allow_null=True)\n\n    def run_validation(self, data):\n        # Empty strings treated as None to avoid unexpected behavior\n        if \"user_args\" in data and data[\"user_args\"] == \"\":\n            data[\"user_args\"] = None\n        if \"language\" in data and data[\"language\"] == \"\":\n            data[\"language\"] = None\n        return super().run_validation(data)\n\n    def update(self, instance, validated_data):\n        if instance.app_logo and \"app_logo\" in validated_data:\n            instance.app_logo.delete()\n        return super().update(instance, validated_data)\n\n    class Meta:\n        model = ApplicationConfiguration\n        fields = \"__all__\"\n", "path": "src/paperless/serialisers.py"}]}