From bbb9c86ba444f49b9410d69e2ec8af8c11673a4a Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Wed, 29 Jul 2026 07:14:13 -0700 Subject: [PATCH] Fix: avoid NotSupportedError from document_importer on MariaDB (#13400) --- .../management/commands/document_importer.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/documents/management/commands/document_importer.py b/src/documents/management/commands/document_importer.py index 90986858b..0e54b0ced 100644 --- a/src/documents/management/commands/document_importer.py +++ b/src/documents/management/commands/document_importer.py @@ -386,10 +386,19 @@ class Command(CryptMixin, PaperlessCommand): raise DeserializationError( f"{model.__name__} has no updatable fields; PK-only models are not supported by the importer", ) + # MySQL/MariaDB support upserts via ON DUPLICATE KEY UPDATE but, + # unlike PostgreSQL/SQLite, cannot target a specific unique field + # for the conflict -- passing unique_fields there raises + # NotSupportedError. + unique_fields = ( + [model._meta.pk.attname] + if connection.features.supports_update_conflicts_with_target + else None + ) model.objects.bulk_create( # type: ignore[attr-defined] instances, update_conflicts=True, - unique_fields=[model._meta.pk.attname], + unique_fields=unique_fields, update_fields=update_fields, ) loaded_models.add(model)