mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix: Dont allow null custom_fields property via API (#5063)
This commit is contained in:
parent
638d9970fd
commit
b1f6f52486
@ -591,7 +591,11 @@ class DocumentSerializer(
|
|||||||
archived_file_name = SerializerMethodField()
|
archived_file_name = SerializerMethodField()
|
||||||
created_date = serializers.DateField(required=False)
|
created_date = serializers.DateField(required=False)
|
||||||
|
|
||||||
custom_fields = CustomFieldInstanceSerializer(many=True, allow_null=True)
|
custom_fields = CustomFieldInstanceSerializer(
|
||||||
|
many=True,
|
||||||
|
allow_null=False,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
owner = serializers.PrimaryKeyRelatedField(
|
owner = serializers.PrimaryKeyRelatedField(
|
||||||
queryset=User.objects.all(),
|
queryset=User.objects.all(),
|
||||||
|
@ -400,6 +400,32 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(CustomFieldInstance.objects.count(), 0)
|
self.assertEqual(CustomFieldInstance.objects.count(), 0)
|
||||||
self.assertEqual(len(doc.custom_fields.all()), 0)
|
self.assertEqual(len(doc.custom_fields.all()), 0)
|
||||||
|
|
||||||
|
def test_custom_field_not_null(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- Existing document
|
||||||
|
WHEN:
|
||||||
|
- API request with custom_fields set to null
|
||||||
|
THEN:
|
||||||
|
- HTTP 400 is returned
|
||||||
|
"""
|
||||||
|
doc = Document.objects.create(
|
||||||
|
title="WOW",
|
||||||
|
content="the content",
|
||||||
|
checksum="123",
|
||||||
|
mime_type="application/pdf",
|
||||||
|
)
|
||||||
|
|
||||||
|
resp = self.client.patch(
|
||||||
|
f"/api/documents/{doc.id}/",
|
||||||
|
data={
|
||||||
|
"custom_fields": None,
|
||||||
|
},
|
||||||
|
format="json",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
def test_bidirectional_doclink_fields(self):
|
def test_bidirectional_doclink_fields(self):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user