Files
dify/api/factories/file_factory/common.py
-LAN- 56593f20b0 refactor(api): continue decoupling dify_graph from API concerns (#33580)
Signed-off-by: -LAN- <laipz8200@outlook.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: WH-2099 <wh2099@pm.me>
2026-03-25 20:32:24 +08:00

28 lines
1.0 KiB
Python

"""Shared helpers for workflow file factory modules."""
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
from core.workflow.file_reference import resolve_file_record_id
def resolve_mapping_file_id(mapping: Mapping[str, Any], *keys: str) -> str | None:
"""Resolve historical file identifiers from persisted mapping payloads.
Workflow and model payloads can outlive file schema changes. Older rows may
still carry concrete identifiers in legacy fields such as ``related_id``,
while newer payloads use opaque references. Keep this compatibility lookup in
the factory layer so historical data remains readable without reintroducing
storage details into graph-layer ``File`` values.
"""
for key in (*keys, "reference", "related_id"):
raw_value = mapping.get(key)
if isinstance(raw_value, str) and raw_value:
resolved_value = resolve_file_record_id(raw_value)
if resolved_value:
return resolved_value
return None