From 27f4133c5de1b721489e9af733038d3dc7394e79 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 23 Oct 2021 15:58:37 -0400 Subject: [PATCH] ensure connection is not None the inspect() API changed in https://github.com/sqlalchemy/sqlalchemy2-stubs/commit/68f8417888456588714fcced1c6799f3eb00ff2d to be more accurate which correctly appears to necessitate a type check in Alembic AutogenContext.inspector() to ensure "self.connection" isn't None Change-Id: Icb3c73be62dc14d9a8f88e0723c3651b6628739a --- alembic/autogenerate/api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/alembic/autogenerate/api.py b/alembic/autogenerate/api.py index 3b23dcd2..27da02c4 100644 --- a/alembic/autogenerate/api.py +++ b/alembic/autogenerate/api.py @@ -341,6 +341,11 @@ class AutogenContext: @util.memoized_property def inspector(self) -> "Inspector": + if self.connection is None: + raise TypeError( + "can't return inspector as this " + "AutogenContext has no database connection" + ) return inspect(self.connection) @contextlib.contextmanager -- 2.47.2