]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove unnecessary filter looking for temp tables
authorMike Barry <michael.barry@gmo.com>
Tue, 25 Oct 2022 20:36:08 +0000 (16:36 -0400)
committerMike Barry <michael.barry@gmo.com>
Tue, 25 Oct 2022 20:40:09 +0000 (16:40 -0400)
Fixes: #8714
lib/sqlalchemy/dialects/mssql/base.py

index fdb0704f6c6c365b03c179b30bd4ffc341ca9a4d..bf2cd9237ed879696fb49d9af532972f6fd59e88 100644 (file)
@@ -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: