Skip to content

Kept env.py failure: the "move it aside" hint is dropped and a full traceback is logged when alembic.ini uses a relative script_location #7856

Open

Description

@masenf

Problem

#7809 made a failing hand-edited alembic/env.py report a one-line error with the fix ("…move it aside and run reflex db init to write the current template") and move the traceback to the debug log, but only when env.py itself raised. That check never matches when alembic.ini has a relative script_location = alembic. The hint is then dropped and the full traceback (~45 lines) is logged at ERROR on every reflex db command and at app startup.

The relative form is what older alembic versions wrote, so it is common in exactly the long-lived apps a kept env.py comes from (for example reflex-examples form-designer and chat_v2). reflex db init with current alembic writes %(here)s/alembic, which works.

Messaging only: exit codes and app start-up are correct, and the separate once-per-process "env.py is not the Reflex template … Move it aside and run reflex db init" warning still appears.

Repro (reflex 0.11.0a2)

  1. reflex init --template blank, add db_url to rxconfig, reflex db init.
  2. Replace alembic/env.py with raise RuntimeError("boom").
  3. In alembic.ini set script_location = alembic (relative).
  4. reflex db status.
script_location rc hint shown traceback lines at ERROR
%(here)s/alembic 1 yes 0
alembic 1 no 15

Cause

reflex/utils/migrations.py: script_directory() returns Path(ScriptDirectory.from_config(config).dir), which is relative (Path("alembic")) for a relative script_location. _raised_in_env_py() compares it with absolute traceback filenames via path.is_relative_to(scripts), which is never true, so it returns False.

Fix

  • Resolve both sides before comparing: scripts = script_directory().resolve() and Path(filename).resolve() for each frame (and for SyntaxError.filename). Alternatively make script_directory() return an absolute path resolved against the alembic.ini directory, which also fixes the relative path printed in the "kept as alembic/env.old" message.
  • Regression test in tests/units/utils/test_migrations.py: the existing custom-env failure test, parametrized over script_location = %(here)s/alembic and script_location = alembic, asserting the hint is present and exc_info is not logged at ERROR in both.

Activity

  1. added
    bugSomething isn't working
    release-trainIssues found during agentic /prerelease-testing fanout, not necessarily validated bugs.
    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

    bugSomething isn't workingrelease-trainIssues found during agentic /prerelease-testing fanout, not necessarily validated bugs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions