Skip to content

Test with flask-sqlalchemy-lite only - #2959

Open
cjmayo wants to merge 2 commits into
pallets-eco:masterfrom
cjmayo:test-flask-sqlalchemy-lite
Open

cjmayo wants to merge 2 commits into
pallets-eco:masterfrom
cjmayo:test-flask-sqlalchemy-lite

Conversation

@cjmayo

@cjmayo cjmayo commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

flask-sqlalchemy-lite without flask-sqlalchemy is not being tested, causing a bug to be missed: #2958

HAS_FLASK_SQLALCHEMY was a way to get this test working. Maybe that needs some more thought.

@ElLorans ElLorans mentioned this pull request Oct 12, 2026
@hasansezertasan

Copy link
Copy Markdown
Member

Thanks @cjmayo for the test job 🤓

I ran py314-flask-sqlalchemy-lite locally and the CI failure is exactly #2958 (ImportError: cannot import name 'T_SESSION'), so the job does what it should. The fix is a one-liner, so could you include it in this PR? That way the job is green here and the test and the fix land together:

# flask_admin/contrib/sqla/_types.py
except ImportError:
    T_SQLALCHEMY: t.Any | None = None  # type: ignore[no-redef]
    T_SESSION: t.Any | None = None  # type: ignore[no-redef]

Once that is in, the job hits one more thing in conftest.py:

NameError: name 'sqla_db_exts' is not defined

sqla_db_exts is only defined inside if HAS_FLASK_SQLALCHEMY:, but the SQLALiteProvider block appends to it. SQLAProvider only imports flask_sqlalchemy in __init__, so it can stay unconditional and only the registration needs the guard:

sqla_db_exts: list[type[T_ANY_SQLA_PROVIDER]] = []
if HAS_FLASK_SQLALCHEMY:
    sqla_db_exts.append(SQLAProvider)

With both, collection works and the tests that don't need services pass locally (220 passed; Postgres/Azure need the CI services). The branch is also behind master, so it needs a rebase. We can then close #2964 as superseded.

WDYT?

@ElLorans

Copy link
Copy Markdown
Collaborator

T_SESSION should import from flask_sqlalchemy_lite though, not be None

@hasansezertasan

Copy link
Copy Markdown
Member

T_SESSION should import from flask_sqlalchemy_lite though, not be None

flask_sqlalchemy_lite only exports SQLAlchemy and has no session class: get_session() returns a plain sqlalchemy.orm.Session. So the lite equivalent would be:

except ImportError:
    T_SQLALCHEMY: t.Any | None = None  # type: ignore[no-redef]
    from sqlalchemy.orm import Session as T_SESSION  # type: ignore[assignment]

I tried it: with lite only, from flask_admin.contrib.sqla import ModelView imports, and the repo's mypy config passes (run with both libraries installed). WDYT?

@cjmayo
cjmayo force-pushed the test-flask-sqlalchemy-lite branch 3 times, most recently from f151e60 to af4d42a Compare October 25, 2026 19:48
cjmayo and others added 2 commits October 25, 2026 19:53
>>> from flask_admin.contrib.sqla import ModelView
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    from flask_admin.contrib.sqla import ModelView
  File "/usr/lib/python3.14/site-packages/flask_admin/contrib/sqla/__init__.py", line 2, in <module>
    from .view import ModelView
  File "/usr/lib/python3.14/site-packages/flask_admin/contrib/sqla/view.py", line 33, in <module>
    from flask_admin.contrib.sqla import form
  File "/usr/lib/python3.14/site-packages/flask_admin/contrib/sqla/form.py", line 47, in <module>
    from ._compat import _get_deprecated_session
  File "/usr/lib/python3.14/site-packages/flask_admin/contrib/sqla/_compat.py", line 7, in <module>
    from flask_admin.contrib.sqla._types import T_SESSION
ImportError: cannot import name 'T_SESSION' from 'flask_admin.contrib.sqla._types' (/usr/lib/python3.14/site-packages/flask_admin/contrib/sqla/_types.py)

Reported-by: me
Co-authored-by: Prakapovich Pavel <flyguy.by@gmail.com>
Co-authored-by: Hasan Sezer Taşan <13135006+hasansezertasan@users.noreply.github.com>
Co-authored-by: Lorenzo <lorenzo.cerreta@gmail.com>
Co-authored-by: Hasan Sezer Taşan <13135006+hasansezertasan@users.noreply.github.com>
@cjmayo
cjmayo force-pushed the test-flask-sqlalchemy-lite branch from af4d42a to 58c1b9e Compare October 25, 2026 19:53
@cjmayo

cjmayo commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

I've rebased, added the fix and updated to be py315-flask-sqlalchemy-lite.

Seems there is more to do:

flask_admin/tests/bootstrap4/test_renders.py:6: in <module>
    from flask_admin.tests.conftest import T_ANY_SQLA_PROVIDER
E   ImportError: cannot import name 'T_ANY_SQLA_PROVIDER' from 'flask_admin.tests.conftest' (/home/runner/work/flask-admin/flask-admin/flask_admin/tests/conftest.py)

@ElLorans

Copy link
Copy Markdown
Collaborator

I can take it from here, if you want.

@cjmayo

cjmayo commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

I can take it from here, if you want.

Yes please!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants