Fix: handle UUIDField created under mariadb and Django 4
This commit is contained in:
parent
335c6c3820
commit
6e84c82a32
@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.1.1 on 2024-10-26 16:14
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
import documents.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("documents", "1055_alter_storagepath_path"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="document",
|
||||
name="transaction_id",
|
||||
field=documents.models.Char32UUIDField(blank=True, null=True),
|
||||
),
|
||||
]
|
@ -134,6 +134,19 @@ class StoragePath(MatchingModel):
|
||||
verbose_name_plural = _("storage paths")
|
||||
|
||||
|
||||
# see https://docs.djangoproject.com/en/5.1/releases/5.0/#migrating-existing-uuidfield-on-mariadb-10-7 and
|
||||
# https://github.com/san4ezy/django_softdelete/issues/45
|
||||
class Char32UUIDField(models.UUIDField):
|
||||
def db_type(self, connection):
|
||||
return "char(32)"
|
||||
|
||||
def get_db_prep_value(self, value, connection, prepared=False):
|
||||
value = super().get_db_prep_value(value, connection, prepared)
|
||||
if value is not None and not isinstance(value, str): # pragma: no cover
|
||||
value = value.hex
|
||||
return value
|
||||
|
||||
|
||||
class Document(SoftDeleteModel, ModelWithOwner):
|
||||
STORAGE_TYPE_UNENCRYPTED = "unencrypted"
|
||||
STORAGE_TYPE_GPG = "gpg"
|
||||
@ -290,6 +303,11 @@ class Document(SoftDeleteModel, ModelWithOwner):
|
||||
),
|
||||
)
|
||||
|
||||
transaction_id = Char32UUIDField(
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-created",)
|
||||
verbose_name = _("document")
|
||||
|
Loading…
x
Reference in New Issue
Block a user