From 80f772a6c0d75dc316b4141d83f502f64a9852bd Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 8 Jan 2024 09:15:17 -0500 Subject: [PATCH] DBAPIConnection can be None for checkin event Fixed the type signature for the :meth:`.PoolEvents.checkin` event to indicate that the given :class:`.DBAPIConnection` argument may be ``None`` in the case where the connection has been invalidated. Change-Id: I4c6f0cf999f2ffb730909e2688eb3b0794ecf2ab (cherry picked from commit 071d3e2d2b11a96fc5a143530357244177259189) --- doc/build/changelog/unreleased_20/checkin_conn_none.rst | 6 ++++++ lib/sqlalchemy/pool/events.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 doc/build/changelog/unreleased_20/checkin_conn_none.rst diff --git a/doc/build/changelog/unreleased_20/checkin_conn_none.rst b/doc/build/changelog/unreleased_20/checkin_conn_none.rst new file mode 100644 index 0000000000..9aeed4784f --- /dev/null +++ b/doc/build/changelog/unreleased_20/checkin_conn_none.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, typing + + Fixed the type signature for the :meth:`.PoolEvents.checkin` event to + indicate that the given :class:`.DBAPIConnection` argument may be ``None`` + in the case where the connection has been invalidated. diff --git a/lib/sqlalchemy/pool/events.py b/lib/sqlalchemy/pool/events.py index 99d180abc9..4b4f4e4785 100644 --- a/lib/sqlalchemy/pool/events.py +++ b/lib/sqlalchemy/pool/events.py @@ -173,7 +173,7 @@ class PoolEvents(event.Events[Pool]): def checkin( self, - dbapi_connection: DBAPIConnection, + dbapi_connection: Optional[DBAPIConnection], connection_record: ConnectionPoolEntry, ) -> None: """Called when a connection returns to the pool. -- 2.47.2