Generated migrations carry an unused import sqlmodel

Open Beginner friendly
#276 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
databases

Research direction

Read alembic/script.py.mako and alembic/env.py, then check the generated migrations to see which ones use SQLModel types. Remove the unconditional import and add a render_item hook that imports SQLModel only when rendering its types; done when autogenerate includes the import only for migrations that need it.

Written by the indexing model from the issue text.

Description

Every migration that alembic revision --autogenerate writes starts with import sqlmodel, because alembic/script.py.mako includes it unconditionally. Alembic writes a SQLModel type such as AutoString as sqlmodel.sql.sqltypes.AutoString() without importing the module, so the migrations that use one need the import. Most migrations use none and carry it unused (8 of the current 13), and since generated migrations are never edited, it stays.

Fix: drop the line from the template, and add a render_item hook in alembic/env.py that adds import sqlmodel to autogen_context.imports when it renders a type from the sqlmodel package, returning False so Alembic still renders the type itself. Existing migrations stay as they are.

Dominant language
Python
Stars
0
Forks
3
Avg merge
1d 11h
Merged PRs (30d)
57

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ukaea/fds

All issues in ukaea/fds

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.