From f21772a8fe905c287f61787c6a294468ff34a6f9 Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Tue, 25 Oct 2022 16:36:08 -0400 Subject: [PATCH] Remove unnecessary filter looking for temp tables Fixes: #8714 --- lib/sqlalchemy/dialects/mssql/base.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index fdb0704f6c..bf2cd9237e 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -3226,26 +3226,13 @@ class MSDialect(default.DefaultDialect): if tablename.startswith("#"): # temporary table # mssql does not support temporary views # SQL Error [4103] [S0001]: "#v": Temporary views are not allowed - tables = ischema.mssql_temp_table_columns - - s = sql.select(tables.c.table_name).where( - tables.c.table_name.like( - self._temp_table_name_like_pattern(tablename) + if bool( + connection.scalar( + text("SELECT object_id(:table_name)"), + {"table_name": "tempdb.dbo.[{}]".format(tablename)}, ) - ) - - # #7168: fetch all (not just first match) in case some other #temp - # table with the same name happens to appear first - table_names = connection.scalars(s).all() - # #6910: verify it's not a temp table from another session - for table_name in table_names: - if bool( - connection.scalar( - text("SELECT object_id(:table_name)"), - {"table_name": "tempdb.dbo.[{}]".format(table_name)}, - ) - ): - return True + ): + return True else: return False else: -- 2.47.3