mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Fix: prune invalid custom fields (#9224)
This commit is contained in:
		@@ -1136,9 +1136,8 @@ 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():
 | 
			
		||||
                        raise serializers.ValidationError(
 | 
			
		||||
                            f"Invalid field: {field}",
 | 
			
		||||
                        )
 | 
			
		||||
                        # In case the field was deleted, just remove from the list
 | 
			
		||||
                        attrs["display_fields"].remove(field)
 | 
			
		||||
                elif field not in SavedView.DisplayFields.values:
 | 
			
		||||
                    raise serializers.ValidationError(
 | 
			
		||||
                        f"Invalid field: {field}",
 | 
			
		||||
 
 | 
			
		||||
@@ -1911,7 +1911,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
 | 
			
		||||
            ],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        # Custom field not found
 | 
			
		||||
        # Custom field not found, removed from list
 | 
			
		||||
        response = self.client.patch(
 | 
			
		||||
            f"/api/saved_views/{v1.id}/",
 | 
			
		||||
            {
 | 
			
		||||
@@ -1923,7 +1923,9 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
 | 
			
		||||
            },
 | 
			
		||||
            format="json",
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 | 
			
		||||
        self.assertEqual(response.status_code, status.HTTP_200_OK)
 | 
			
		||||
        v1.refresh_from_db()
 | 
			
		||||
        self.assertNotIn(SavedView.DisplayFields.CUSTOM_FIELD % 99, v1.display_fields)
 | 
			
		||||
 | 
			
		||||
    def test_get_logs(self):
 | 
			
		||||
        log_data = "test\ntest2\n"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user