# Buggy code
def is_disconnect(self, e, connection, cursor):
    if isinstance(e, self.dbapi.Error):
        code = e.args[0]
        if code in (
            "08S01",
            "01002",
            "08003",
            "08007",
            "08S02",
            "08001",
            "HYT00",
            "HY010",
            "10054",
        ):
            return True
    return super(MSDialect_pyodbc, self).is_disconnect(e, connection, cursor)


# Traceback (pyodbc.Error)
restart done?
Traceback (most recent call last):
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\default.py", line 593, in do_execute
cursor.execute(statement, parameters)
pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (WrapperWrite()). (233) (SQLExecDirectW); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]Allgemeiner Netzwerkfehler. Weitere Informationen finden Sie in der Dokumentation über Netzwerke. (11)')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:/Users/xxx/PycharmProjects/sqlalchemy_bug/main.py", line 12, in <module>
session.execute('SELECT 1')
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\orm\session.py", line 1291, in execute
return self._connection_for_bind(bind, close_with_result=True).execute(
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1011, in execute
return meth(self, multiparams, params)
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\sql\elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1316, in _execute_context
self._handle_dbapi_exception(
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1510, in _handle_dbapi_exception
util.raise_(
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\util\compat.py", line 182, in raise_
raise exception
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\default.py", line 593, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (WrapperWrite()). (233) (SQLExecDirectW); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]Allgemeiner Netzwerkfehler. Weitere Informationen finden Sie in der Dokumentation über Netzwerke. (11)')
[SQL: SELECT 1]
(Background on this error at: http://sqlalche.me/e/13/dbapi)
Exception during reset or similar
Traceback (most recent call last):
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\pool\base.py", line 697, in _finalize_fairy
fairy._reset(pool)
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\pool\base.py", line 893, in _reset
pool._dialect.do_rollback(self)
File "C:\Users\xxx\PycharmProjects\sqlalchemy_bug\.venv\lib\site-packages\sqlalchemy\engine\default.py", line 543, in do_rollback
dbapi_connection.rollback()
pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Kommunikationsverbindungsfehler (0) (SQLEndTran)')

# Fixed code
def is_disconnect(self, e, connection, cursor):
    if isinstance(e, self.dbapi.Error):
        code = e.args[0]
        if code in {
            "08S01",
            "01000",
            "01002",
            "08003",
            "08007",
            "08S02",
            "08001",
            "HYT00",
            "HY010",
            "10054",
        }:
            return True
    return super(MSDialect_pyodbc, self).is_disconnect(e, connection, cursor)