Skip to content

File snapshots are not restored inside an untyped container #424

Open

Description

@Luckyou-d

Problem

ArrayAnySegment snapshots a file so it can be rebuilt after serialisation: serialize_file_snapshot dumps the value, walks the result and records where the files sit, and _restore_files puts them back. The walk only recognises SerializedFile, the shape the marker produces while pydantic goes through a model:

def _collect_file_paths(value, paths, path=()):
    if isinstance(value, SerializedFile):
        if paths is not None:
            paths.append(path)
        return value.data

An untyped container is dumped as it is - a deque keeps its elements, and a File inside it stays a File, never SerializedFile. No path is recorded, so the restore step has nothing to restore and the file stays the plain dict pydantic produced later.

An existing test covers it and fails on main:

tests/variables/test_file_snapshots.py::test_snapshots_preserve_files_inside_serializable_models[python]
E  assert [{'dify_model_identity': '__dify__file__', ...}] == [File(...), {...}]

Both parametrisations ([python] and [json]) fail, and it is not platform-dependent: every other container in that test is a model, which is why only the deque case shows it.

Expected

A File inside an untyped container round-trips as a File, like the ones inside models and lists.

Fix

Record the path for a File too, and let it through unchanged so the later dump serialises it as before. PR to follow.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions