mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix symmetric doc links with target value None (#5187)
This commit is contained in:
parent
b93f655039
commit
c5d622279c
@ -566,6 +566,9 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):
|
||||
value_document_ids=[document.id],
|
||||
),
|
||||
)
|
||||
elif target_doc_field_instance.value is None:
|
||||
target_doc_field_instance.value_document_ids = [document.id]
|
||||
custom_field_instances_to_update.append(target_doc_field_instance)
|
||||
elif document.id not in target_doc_field_instance.value:
|
||||
target_doc_field_instance.value_document_ids.append(document.id)
|
||||
custom_field_instances_to_update.append(target_doc_field_instance)
|
||||
|
@ -530,7 +530,7 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
||||
|
||||
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def test_bidirectional_doclink_fields(self):
|
||||
def test_symmetric_doclink_fields(self):
|
||||
"""
|
||||
GIVEN:
|
||||
- Existing document
|
||||
@ -637,3 +637,28 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(doc2.custom_fields.first().value, [])
|
||||
self.assertEqual(doc3.custom_fields.first().value, [4])
|
||||
self.assertEqual(doc4.custom_fields.first().value, [3])
|
||||
|
||||
# If field exists on target doc but value is None
|
||||
doc5 = Document.objects.create(
|
||||
title="WOW5",
|
||||
content="the content4",
|
||||
checksum="5",
|
||||
mime_type="application/pdf",
|
||||
)
|
||||
CustomFieldInstance.objects.create(document=doc5, field=custom_field_doclink)
|
||||
|
||||
resp = self.client.patch(
|
||||
f"/api/documents/{doc1.id}/",
|
||||
data={
|
||||
"custom_fields": [
|
||||
{
|
||||
"field": custom_field_doclink.id,
|
||||
"value": [doc5.id],
|
||||
},
|
||||
],
|
||||
},
|
||||
format="json",
|
||||
)
|
||||
|
||||
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(doc5.custom_fields.first().value, [1])
|
||||
|
Loading…
x
Reference in New Issue
Block a user