fix: resolve relative alembic script_location before matching frames

MA
15h ago
+90-20

Closes #7856

With script_location = alembic (relative) in alembic.ini, script_directory() returns Path("alembic"), and _raised_in_env_py() compared it with absolute traceback file names using is_relative_to, which never matched. A failing hand-edited env.py was then logged at ERROR with its full traceback instead of the one-line "move it aside and run reflex db init" hint.

  • _raised_in_env_py() now resolves the script directory and each traceback / SyntaxError file name (Path.resolve()) before comparing them, as suggested in the issue. Resolving rather than only making the paths absolute matters because alembic loads revision scripts by their real path (ScriptDirectory._load_revisions calls file_path.resolve()), so a revision frame only lines up with a script directory that is resolved too. script_directory() itself is unchanged, so its other callers behave as before.
  • Bugfix news fragment added.

Tests:

  • test_custom_env_failure_is_reported_with_the_fix and test_custom_env_syntax_error_is_reported_with_the_fix are parametrized over script_location = %(here)s/alembic and script_location = alembic.
  • _assert_env_failure_reported now takes the expected first line and asserts the single ERROR record equals it plus CUSTOM_ENV_HINT, with no exc_info. The SyntaxError case derives its expected message by compiling the same source.
  • test_revision_script_failure_keeps_its_traceback gains a case where ALEMBIC_CONFIG reaches alembic.ini through a symlinked directory: the revision failure must keep its traceback and get no hint. This case fails on main and would also fail if the paths were only made absolute (os.path.abspath) instead of resolved.
  • On main, 3 of the new/changed cases fail (the two relative script_location cases and the symlinked config case).

pytest tests/units/utils/test_migrations.py: 46 passed; pytest tests/units/test_model.py tests/units/test_prerequisites.py tests/units/test_reflex.py: 218 passed, 2 skipped; ruff check/format and pyright on the changed files clean.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?