fix: show a knowledge file's current name in citations after it is renamed (#31860)

This commit is contained in:
G30 authored and GitHub committed 2026-10-10 20:44:43 +04:00
1 parent 0c3f74c9c1
commit 94e9c7fef9
2 files changed
+31

No files matched your search

+18
View File
@@ -1704,6 +1704,24 @@ async def get_sources_from_items(
sources.append(source)
except Exception as e:
log.exception(e)
file_ids = {
metadata['file_id']
for source in sources
for metadata in source['metadata']
if isinstance(metadata, dict) and metadata.get('file_id')
}
if file_ids:
file_names = {
file.id: (file.meta or {}).get('name') for file in await Files.get_file_metadatas_by_ids(list(file_ids))
}
for source in sources:
for metadata in source['metadata']:
file_name = file_names.get(metadata.get('file_id')) if isinstance(metadata, dict) else None
if file_name:
if metadata.get('source') == metadata.get('name'):
metadata['source'] = file_name
metadata['name'] = file_name
return sources