Fix: change async handling of select custom field updates (#11490)

This commit is contained in:
shamoon
2025-11-29 19:54:15 -08:00
committed by GitHub
parent 67d079fe14
commit 0c43b50f01
3 changed files with 77 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
import json
from datetime import date
from unittest import mock
from unittest.mock import ANY
from django.contrib.auth.models import Permission
@@ -276,6 +277,52 @@ class TestCustomFieldsAPI(DirectoriesMixin, APITestCase):
doc.refresh_from_db()
self.assertEqual(doc.custom_fields.first().value, None)
@mock.patch("documents.signals.handlers.process_cf_select_update.delay")
def test_custom_field_update_offloaded_once(self, mock_delay):
"""
GIVEN:
- A select custom field attached to multiple documents
WHEN:
- The select options are updated
THEN:
- The async update task is enqueued once
"""
cf_select = CustomField.objects.create(
name="Select Field",
data_type=CustomField.FieldDataType.SELECT,
extra_data={
"select_options": [
{"label": "Option 1", "id": "abc-123"},
{"label": "Option 2", "id": "def-456"},
],
},
)
documents = [
Document.objects.create(
title="WOW",
content="the content",
checksum=f"{i}",
mime_type="application/pdf",
)
for i in range(3)
]
for document in documents:
CustomFieldInstance.objects.create(
document=document,
field=cf_select,
value_select="def-456",
)
cf_select.extra_data = {
"select_options": [
{"label": "Option 1", "id": "abc-123"},
],
}
cf_select.save()
mock_delay.assert_called_once_with(cf_select)
def test_custom_field_select_old_version(self):
"""
GIVEN: