From 6d6c54db19bbaaa594d07f3362447e2c379a2778 Mon Sep 17 00:00:00 2001 From: Levi <81591061+levischd@users.noreply.github.com> Date: Thu, 12 Feb 2026 12:48:51 +0100 Subject: [PATCH] fix(metadata): handle unhashable list values in metadata split (#13116) ### What problem does this PR solve? This PR fixes missing metadata on documents synced from the Moodle connector, especially for **Book** modules. Background: - Moodle Book metadata includes fields like `chapters`, which is a `list[dict]`. - During metadata normalization in `DocMetadataService._split_combined_values`, list deduplication used `dict.fromkeys(...)`. - `dict.fromkeys(...)` fails for unhashable values (like `dict`), causing metadata update to fail. - Result: documents were imported, but metadata was not saved for affected module types (notably Books). What this PR changes: - Replaces hash-based list deduplication with `dedupe_list(...)`, which safely handles unhashable list items while preserving order. - This allows Book metadata (and other complex list metadata) to be persisted correctly. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): Contribution during my time at RAGcon GmbH. --- api/db/services/doc_metadata_service.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/db/services/doc_metadata_service.py b/api/db/services/doc_metadata_service.py index 339d51c308..69f25de485 100644 --- a/api/db/services/doc_metadata_service.py +++ b/api/db/services/doc_metadata_service.py @@ -231,8 +231,9 @@ class DocMetadataService: new_values.append(item) else: new_values.append(item) - # Remove duplicates while preserving order - processed[key] = list(dict.fromkeys(new_values)) + # Remove duplicates while preserving order. + # Use string-based dedupe to support unhashable values (e.g. dict entries). + processed[key] = dedupe_list(new_values) else: processed[key] = value