@@ -164,9 +164,15 @@ def set_current_catalog(self, catalog_name: t.Optional[str]) -> None:
164164 https://learn.microsoft.com/en-us/fabric/data-warehouse/sql-query-editor#limitations
165165 """
166166 target_catalog = self ._normalize_catalog (catalog_name )
167+ explicit_default_catalog = catalog_name is not None and target_catalog is None
168+ connected_catalog = self ._normalize_catalog (self ._connected_catalog )
167169
168- # No-op: the logical catalog state already matches.
169- if self .get_current_catalog () == target_catalog :
170+ # An explicit request for the default catalog must also match the catalog
171+ # used by the open connection. A lazy restore with None only updates the
172+ # logical target and intentionally leaves that connection in place.
173+ if self .get_current_catalog () == target_catalog and (
174+ not explicit_default_catalog or connected_catalog is None
175+ ):
170176 logger .debug ("Already using requested Fabric catalog state, no action needed" )
171177 return
172178
@@ -186,8 +192,9 @@ def set_current_catalog(self, catalog_name: t.Optional[str]) -> None:
186192 # open connection is already on a different catalog. If a previous
187193 # restore-to-neutral left the connection on the right catalog, we
188194 # skip the close entirely.
189- connected_catalog = self ._normalize_catalog (self ._connected_catalog )
190- needs_reconnect = target_catalog is not None and connected_catalog != target_catalog
195+ needs_reconnect = (target_catalog is not None or explicit_default_catalog ) and (
196+ connected_catalog != target_catalog
197+ )
191198
192199 if needs_reconnect :
193200 logger .info (
0 commit comments