Skip to content

reflex export crashes with a traceback (and leaves a partial backend.zip) on a directory symlink pointing outside the app or a dangling symlink #7851

Open

Description

@masenf

Problem

The backend zip is built by _zip() in reflex/utils/build.py. It walks the app directory with os.walk(root_directory, followlinks=True), resolves every directory (Path(directory_path).resolve()) and stores each file under file.relative_to(root_directory). Three common layouts break it:

  1. A directory symlink that resolves outside the app (a shared common/ package linked into the app in a monorepo): relative_to raises ValueError: '/elsewhere/common/x.py' is not in the subpath of '/app'. reflex export prints a traceback and leaves a partial backend.zip.
  2. A dangling symlink (to a deleted file): os.walk lists it as a file and zipf.write raises FileNotFoundError, same outcome.
  3. A directory symlink inside the app (pointing to another directory of the same app): its files are written twice under two names (duplicate zip entries; the archive contains both copies).

reflex deploy catches the error and prints a one-line message without uploading, so the deploy is safe, but reflex export users get a raw traceback. File symlinks are archived by content and work. Not a regression; last verified on 0.10.1a1, and the code is unchanged on main.

Repro

reflex init --template blank   # in /tmp/app
mkdir -p /tmp/shared && echo "X = 1" > /tmp/shared/mod.py
ln -s /tmp/shared /tmp/app/shared           # case 1
ln -s /tmp/app/does-not-exist /tmp/app/gone # case 2
reflex export --backend-only

Expected

  • Case 1: the linked directory's files are archived under the link's path inside the app (shared/mod.py), since followlinks=True says links are followed; or, if links outside the app are not wanted, they are skipped with one warning naming the link. Either way, no traceback.
  • Case 2: the dangling link is skipped with a warning.
  • Case 3: each file is archived once.

Fix direction

  • Code: _zip() in reflex/utils/build.py.
  • Compute archive names from the unresolved walk path (Path(directory_path) relative to the unresolved root) instead of resolving each directory, so a followed link keeps its in-app path; keep using resolved paths only for loop and duplicate detection (track (st_dev, st_ino) of visited directories to skip a directory reached twice, which also guards against symlink loops).
  • Skip and warn for entries that do not exist (Path.exists() is False for a dangling link).
  • Keep the existing exclusions (hidden entries, venvs, .db files, files_to_exclude) working on the unresolved paths.
  • Tests: unit tests in tests/units/utils/test_build.py (or the existing zip tests) for the three cases, using tmp_path and os.symlink (skip on Windows when symlinks are unavailable).

Activity

  1. added
    bug
    release-train
    on Nov 11, 2026
  2. linear-code commented on Nov 11, 2026

    @linear-code
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

    bugrelease-train

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions