mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-12 00:19:48 +00:00
Fix: handle uuid fields created under mariadb and Django 4 (#8034)
This commit is contained in:
@@ -15,6 +15,7 @@ from django.conf import settings
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.cache import cache
|
||||
from django.db import DataError
|
||||
from django.test import override_settings
|
||||
from django.utils import timezone
|
||||
from guardian.shortcuts import assign_perm
|
||||
@@ -2605,6 +2606,35 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(doc1.tags.count(), 2)
|
||||
|
||||
@mock.patch("django_softdelete.models.SoftDeleteModel.delete")
|
||||
def test_warn_on_delete_with_old_uuid_field(self, mocked_delete):
|
||||
"""
|
||||
GIVEN:
|
||||
- Existing document in a (mocked) MariaDB database with an old UUID field
|
||||
WHEN:
|
||||
- API request to delete document is made which raises "Data too long for column" error
|
||||
THEN:
|
||||
- Warning is logged alerting the user of the issue (and link to the fix)
|
||||
"""
|
||||
|
||||
doc = Document.objects.create(
|
||||
title="test",
|
||||
mime_type="application/pdf",
|
||||
content="this is a document 1",
|
||||
checksum="1",
|
||||
)
|
||||
|
||||
mocked_delete.side_effect = DataError(
|
||||
"Data too long for column 'transaction_id' at row 1",
|
||||
)
|
||||
|
||||
with self.assertLogs(level="WARNING") as cm:
|
||||
self.client.delete(f"/api/documents/{doc.pk}/")
|
||||
self.assertIn(
|
||||
"Detected a possible incompatible database column",
|
||||
cm.output[0],
|
||||
)
|
||||
|
||||
|
||||
class TestDocumentApiV2(DirectoriesMixin, APITestCase):
|
||||
def setUp(self):
|
||||
|
@@ -327,6 +327,15 @@ class TestBulkEdit(DirectoriesMixin, TestCase):
|
||||
)
|
||||
self.assertEqual(groups_with_perms.count(), 2)
|
||||
|
||||
@mock.patch("documents.models.Document.delete")
|
||||
def test_delete_documents_old_uuid_field(self, m):
|
||||
m.side_effect = Exception("Data too long for column 'transaction_id' at row 1")
|
||||
doc_ids = [self.doc1.id, self.doc2.id, self.doc3.id]
|
||||
bulk_edit.delete(doc_ids)
|
||||
with self.assertLogs(level="WARNING") as cm:
|
||||
bulk_edit.delete(doc_ids)
|
||||
self.assertIn("possible incompatible database column", cm.output[0])
|
||||
|
||||
|
||||
class TestPDFActions(DirectoriesMixin, TestCase):
|
||||
def setUp(self):
|
||||
|
@@ -3,6 +3,7 @@ import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
@@ -238,3 +239,16 @@ class TestSanityChecker(DirectoriesMixin, TestCase):
|
||||
|
||||
self.assertEqual(len(capture.output), 2)
|
||||
self.assertIn("Checksum mismatch. Stored: abc, actual:", capture.output[1])
|
||||
|
||||
|
||||
class TestConvertMariaDBUUID(TestCase):
|
||||
@mock.patch("django.db.connection.schema_editor")
|
||||
def test_convert(self, m):
|
||||
m.alter_field.return_value = None
|
||||
|
||||
stdout = StringIO()
|
||||
call_command("convert_mariadb_uuid", stdout=stdout)
|
||||
|
||||
m.assert_called_once()
|
||||
|
||||
self.assertIn("Successfully converted", stdout.getvalue())
|
||||
|
Reference in New Issue
Block a user