@@ -170,9 +170,15 @@ def set_current_catalog(self, catalog_name: t.Optional[str]) -> None:
170170 https://learn.microsoft.com/en-us/fabric/data-warehouse/sql-query-editor#limitations
171171 """
172172 target_catalog = self ._normalize_catalog (catalog_name )
173+ explicit_default_catalog = catalog_name is not None and target_catalog is None
174+ connected_catalog = self ._normalize_catalog (self ._connected_catalog )
173175
174- # No-op: the logical catalog state already matches.
175- if self .get_current_catalog () == target_catalog :
176+ # An explicit request for the default catalog must also match the catalog
177+ # used by the open connection. A lazy restore with None only updates the
178+ # logical target and intentionally leaves that connection in place.
179+ if self .get_current_catalog () == target_catalog and (
180+ not explicit_default_catalog or connected_catalog is None
181+ ):
176182 logger .debug ("Already using requested Fabric catalog state, no action needed" )
177183 return
178184
@@ -192,8 +198,9 @@ def set_current_catalog(self, catalog_name: t.Optional[str]) -> None:
192198 # open connection is already on a different catalog. If a previous
193199 # restore-to-neutral left the connection on the right catalog, we
194200 # skip the close entirely.
195- connected_catalog = self ._normalize_catalog (self ._connected_catalog )
196- needs_reconnect = target_catalog is not None and connected_catalog != target_catalog
201+ needs_reconnect = (target_catalog is not None or explicit_default_catalog ) and (
202+ connected_catalog != target_catalog
203+ )
197204
198205 if needs_reconnect :
199206 logger .info (
0 commit comments