From 4da973f6a534b338422e3f5a775699e9f4fc1bb2 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 25 Feb 2025 23:34:29 -0800 Subject: [PATCH] Revert "Fix: prune invalid custom fields (#9224)" This reverts commit 61cb5103ed96dbe6a4f44129f92616b4c0d99b45. --- src/documents/serialisers.py | 5 +++-- src/documents/tests/test_api_documents.py | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 5f3b310c2..a486fe241 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1136,8 +1136,9 @@ class SavedViewSerializer(OwnedObjectSerializer): ): # i.e. check for 'custom_field_' prefix field_id = int(re.search(r"\d+", field)[0]) if not CustomField.objects.filter(id=field_id).exists(): - # In case the field was deleted, just remove from the list - attrs["display_fields"].remove(field) + raise serializers.ValidationError( + f"Invalid field: {field}", + ) elif field not in SavedView.DisplayFields.values: raise serializers.ValidationError( f"Invalid field: {field}", diff --git a/src/documents/tests/test_api_documents.py b/src/documents/tests/test_api_documents.py index 40c30f5bb..28261b392 100644 --- a/src/documents/tests/test_api_documents.py +++ b/src/documents/tests/test_api_documents.py @@ -1911,7 +1911,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): ], ) - # Custom field not found, removed from list + # Custom field not found response = self.client.patch( f"/api/saved_views/{v1.id}/", { @@ -1923,9 +1923,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): }, format="json", ) - self.assertEqual(response.status_code, status.HTTP_200_OK) - v1.refresh_from_db() - self.assertNotIn(SavedView.DisplayFields.CUSTOM_FIELD % 99, v1.display_fields) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_get_logs(self): log_data = "test\ntest2\n"