fix: resolve relative alembic script_location before matching frames
MA
15h ago+90+90+01234567890123456789-20-20-01234567890123456789
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 /SyntaxErrorfile 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_revisionscallsfile_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_fixandtest_custom_env_syntax_error_is_reported_with_the_fixare parametrized overscript_location = %(here)s/alembicandscript_location = alembic._assert_env_failure_reportednow takes the expected first line and asserts the single ERROR record equals it plusCUSTOM_ENV_HINT, with noexc_info. The SyntaxError case derives its expected message by compiling the same source.test_revision_script_failure_keeps_its_tracebackgains a case whereALEMBIC_CONFIGreachesalembic.inithrough a symlinked directory: the revision failure must keep its traceback and get no hint. This case fails onmainand 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 relativescript_locationcases 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?