You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Somewhere around 2025-09-08, Fabric started validating the "Database=" connection argument and throwing 'Authentication failed' if the database doesnt exist
122
-
# In addition, set_current_catalog() is implemented using a threadlocal variable "target_catalog"
123
-
# So, when we drop a warehouse, and there are still threads with "target_catalog" set to reference it, any operations on those threads
124
-
# that use an either use an existing connection pointing to this warehouse or trigger a new connection
125
-
# will fail with an 'Authentication Failed' error unless we close all connections here, which also clears all the threadlocal data
128
+
# Close all connections if any thread may be using the dropped warehouse.
129
+
# We must check both the logical target and the physical connection catalog
130
+
# (falling back to the configured default when either is neutral) because
131
+
# Fabric validates the DATABASE= connection argument and raises
132
+
# 'Authentication Failed' when it points at a non-existent warehouse.
# commit the transaction before closing the connection to help prevent errors like:
167
-
# > Snapshot isolation transaction failed in database because the object accessed by the statement has been modified by a
168
-
# > DDL statement in another concurrent transaction since the start of this transaction
169
-
# on subsequent queries in the new connection
170
-
self._connection_pool.commit()
195
+
ifneeds_reconnect:
196
+
logger.info(
197
+
"Switching connection from catalog '%s' to '%s'",
198
+
self._catalog_state_label(connected_catalog),
199
+
self._catalog_state_label(target_catalog),
200
+
)
201
+
# Commit before closing to avoid snapshot-isolation errors on
202
+
# subsequent queries in the new connection.
203
+
self._connection_pool.commit()
204
+
# note: close() on the pool (not self.close()) to only affect this
205
+
# thread's connection rather than all threads.
206
+
self._connection_pool.close()
207
+
self._connected_catalog=target_catalog
208
+
else:
209
+
logger.debug(
210
+
"Updating catalog target to '%s' (connection remains on '%s')",
211
+
self._catalog_state_label(target_catalog),
212
+
self._catalog_state_label(connected_catalog),
213
+
)
171
214
172
-
# note: we call close() on the connection pool instead of self.close() because self.close() calls close_all()
173
-
# on the connection pool but we just want to close the connection for this thread
174
-
self._connection_pool.close()
175
215
self._target_catalog=target_catalog
176
216
177
-
catalog_after_switch=self.get_current_catalog()
178
-
179
-
ifcatalog_after_switch!=target_catalog:
180
-
# We need to raise an error if the catalog switch failed to prevent the operation that needed the catalog switch from being run against the wrong catalog
181
-
raiseSQLMeshError(
182
-
f"Unable to switch catalog to {target_catalog}, catalog ended up as {catalog_after_switch}"
0 commit comments