Skip to content

fix(alembic): put the project root on sys.path for the migrations - #2598

Merged
lbesson merged 1 commit into
masterfrom
fix/alembic-sys-path
Nov 5, 2026
Merged

lbesson merged 1 commit into
masterfrom
fix/alembic-sys-path

Conversation

@lbesson

@lbesson lbesson commented Nov 5, 2026

Copy link
Copy Markdown
Member

Follow-up of #2593, found while running the migration of v6.29.0 in production.

With alembic.ini rendered by the entrypoint (#2593), the command of the wiki connected to the database, then failed:

docker-compose run --rm --no-deps api alembic current
...
  File "/var/www/alembic_migration/versions/06d2a35e39c8_improve_serac_database.py", line 11, in <module>
    from alembic_migration.extensions import drop_enum
ModuleNotFoundError: No module named 'alembic_migration'

Ten migrations import alembic_migration.extensions. In the image, the project is installed non-editable, and /opt/venv/bin/alembic does not put the current directory on sys.path. Locally, the editable install hid it. The migration of v6.29.0 ran with -e PYTHONPATH=/var/www.

alembic.ini.in now sets prepend_sys_path = . (the working directory of the image, /var/www), with path_separator = os as alembic 1.20 requires alongside it.

Checked: python -I (no current directory on sys.path, as in the image) running alembic heads failed with the same error before, and gives a7c3e1f05b2d (head) after, with deprecation warnings as errors.

🤖 Generated with Claude Code

Ten migrations import alembic_migration.extensions. In the image, the
project is installed non-editable and /opt/venv/bin/alembic does not
put the current directory on sys.path: `alembic current` failed with
"No module named 'alembic_migration'" on the production server, and the
v6.29.0 migration ran with PYTHONPATH=/var/www.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@lbesson
lbesson merged commit fb83f4b into master Nov 5, 2026
7 checks passed
@lbesson
lbesson deleted the fix/alembic-sys-path branch November 5, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant