test: add coverage for alternate version_path spellings - #1847
test: add coverage for alternate version_path spellings#1847MohammedAlkindi wants to merge 2 commits into
Conversation
Issue sqlalchemy#1366 reported that ``alembic revision --version-path`` rejected a directory that was in fact configured, on Windows, when the drive letter's case differed from the configuration. The matching in ScriptDirectory.generate_revision() moved to pathlib in 1.16.0, which resolved it, but nothing in the suite pinned the behaviour. Confirmed on Windows 11 against a multi-head project whose version locations contain spaces: on 1.19.2 the configured spelling, either drive letter case, and a trailing separator are all accepted. Adds a test asserting the revision lands in the configured directory when the path carries a trailing separator and, where a drive letter exists, when its case is swapped. Swapping the case-insensitive Path comparison for a string comparison fails this test alone and none of the existing ones, so it covers ground the suite did not. Fixes: sqlalchemy#1366
CaselIT
left a comment
There was a problem hiding this comment.
thanks, looks ok, just a note regarding the changelog
| @@ -0,0 +1,9 @@ | |||
| .. change:: | |||
| :tags: bug, tests | |||
There was a problem hiding this comment.
I think it would make more sense to remove this changelog, since there are no code changes and from an user point of view the fact that we only added a test isn't really useful
There was a problem hiding this comment.
Agreed, removed — no code change, so there is nothing for a user to act on. The PR is now just the test.
pytest tests/test_script_production.py::MultiDirRevisionCommandTest -> 5 passed after the removal.
Review feedback: the change adds no code, so a changelog entry saying a test was added carries nothing a user would act on.
|
This has been approved since 2026-08-11 with all seven CI checks green, but |
|
Sorry i forgot to move it to gerri |
sqla-tester
left a comment
There was a problem hiding this comment.
OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 2d1f834 of this pull request into gerrit so we can run tests and reviews and stuff
|
New Gerrit review created for change 2d1f834: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6909 |
Closes #1366
@zzzeek asked on the issue for this to be "confirmed as fixed and maybe even a test added to confirm it" — this does both. I'm on Windows 11, so I could exercise the reported paths directly rather than reason about them.
Confirmed fixed
Built a multi-head project whose version locations contain spaces, seeded a head in each, then created a revision naming the same directory five different ways. On 1.19.2:
--version-pathc:\…)C:\…)So the original report — drive-letter capitalisation — is genuinely resolved by the move to
pathlib, exactly as you expected.PureWindowsPath.__eq__is case-insensitive, so.absolute() == .absolute()handles it.The test
Nothing pinned that.
MultiDirRevisionCommandTestgains one test asserting a revision lands in the configured directory when the path carries a trailing separator, and — where a drive letter exists — when its case is swapped. It is written to be portable rather than skipped:os.path.splitdrivereturns an empty drive on POSIX, so only the trailing-separator spelling runs there.To check it has teeth, I replaced the case-insensitive
Pathcomparison ingenerate_revision()with a string comparison:Only the new test fails; the four existing tests in that class still pass. Reverting the whole comparison to raw strings fails the new test plus two existing ones. So it covers ground the suite did not.
Two spellings that still fail — deliberately not changed here
While testing I found the same error is still raised for two other spellings of a configured directory:
..—…\migrations\zzz\..\versions beforeC:\…\Temp\ALEMBI~3\MYPROJ~1\MIGRAT~1\VERSIO~1Both are the same cause:
Path.absolute()normalises neither, whilePath.resolve()handles both (verified directly). I have not touched that, because switching toresolve()also starts following symlinks, which is a behaviour decision for you rather than something to slip into a test PR. Happy to open a separate issue or PR if you want it changed.On the "spaces" reports in this thread
@Tayyab-H and @SalamM1 reported failures whenever the path contained spaces, which didn't match what I measured. It reproduces exactly when
path_separatoris absent from the config: alembic then falls back to legacy splitting on spaces and commas, which cuts any path containing a space in half. Same project, same path, only that key differing:A
DeprecationWarningis emitted, butDeprecationWarningis hidden by default outside__main__, so it never reaches the user and they see only the confusing path error.alembic inithas writtenpath_separator = ossince 1.16.0, so this only affects configs predating that. That may be worth its own issue — say the word and I'll file it rather than widen this PR.Testing
Windows 11, Python 3.13, alembic 1.19.2, SQLAlchemy 2.0.51.
pytest tests/— 1814 passed, 5 failed, 132 skipped. The 5 failures are allScriptNamingTesttimezone tests failing on a cleanmaincheckout too (zoneinfohas no system tzdata on Windows); identical before and after this change, verified by stashing it and re-running. No new failures.tests/test_script_production.pyalone: 39 passed on cleanmain, 40 with this change — same 5 pre-existing failures.black --check,flake8andzimports --diffare clean on the changed file.