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
128
-
# In addition, set_current_catalog() is implemented using a threadlocal variable "target_catalog"
129
-
# So, when we drop a warehouse, and there are still threads with "target_catalog" set to reference it, any operations on those threads
130
-
# that use an either use an existing connection pointing to this warehouse or trigger a new connection
131
-
# will fail with an 'Authentication Failed' error unless we close all connections here, which also clears all the threadlocal data
134
+
# Close all connections if any thread may be using the dropped warehouse.
135
+
# We must check both the logical target and the physical connection catalog
136
+
# (falling back to the configured default when either is neutral) because
137
+
# Fabric validates the DATABASE= connection argument and raises
138
+
# 'Authentication Failed' when it points at a non-existent warehouse.
# commit the transaction before closing the connection to help prevent errors like:
173
-
# > Snapshot isolation transaction failed in database because the object accessed by the statement has been modified by a
174
-
# > DDL statement in another concurrent transaction since the start of this transaction
175
-
# on subsequent queries in the new connection
176
-
self._connection_pool.commit()
201
+
ifneeds_reconnect:
202
+
logger.info(
203
+
"Switching connection from catalog '%s' to '%s'",
204
+
self._catalog_state_label(connected_catalog),
205
+
self._catalog_state_label(target_catalog),
206
+
)
207
+
# Commit before closing to avoid snapshot-isolation errors on
208
+
# subsequent queries in the new connection.
209
+
self._connection_pool.commit()
210
+
# note: close() on the pool (not self.close()) to only affect this
211
+
# thread's connection rather than all threads.
212
+
self._connection_pool.close()
213
+
self._connected_catalog=target_catalog
214
+
else:
215
+
logger.debug(
216
+
"Updating catalog target to '%s' (connection remains on '%s')",
217
+
self._catalog_state_label(target_catalog),
218
+
self._catalog_state_label(connected_catalog),
219
+
)
177
220
178
-
# note: we call close() on the connection pool instead of self.close() because self.close() calls close_all()
179
-
# on the connection pool but we just want to close the connection for this thread
180
-
self._connection_pool.close()
181
221
self._target_catalog=target_catalog
182
222
183
-
catalog_after_switch=self.get_current_catalog()
184
-
185
-
ifcatalog_after_switch!=target_catalog:
186
-
# 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
187
-
raiseSQLMeshError(
188
-
f"Unable to switch catalog to {target_catalog}, catalog ended up as {catalog_after_switch}"
0 commit comments