Skip to content

fix: powerquery load-to connection-only is a no-op on already-loaded queries #498

@sbroenne

Description

@sbroenne

Problem

Running \�xcelcli powerquery load-to --destination connection-only\ on a query that was already loaded to a worksheet returned \success: true\ but left the ListObject and connection in place — a silent no-op.

Steps to Reproduce

\\powershell
excelcli powerquery create --file Book.xlsx --query PQ1 --mcode 'let s = 1 in s' --destination worksheet
excelcli powerquery load-to --file Book.xlsx --query PQ1 --destination connection-only
excelcli powerquery get-load-config --file Book.xlsx --query PQ1

Returns loadMode: LoadToTable instead of ConnectionOnly

\\

Root Cause

The ConnectionOnly case in PowerQueryCommands.LoadTo.cs assumed the query was already connection-only and returned early without calling UnloadFromDestinations.

Fix

LoadTo now always calls UnloadFromDestinations before applying any new load mode, covering all state transitions in all directions (LoadToTable→ConnectionOnly, LoadToBoth→ConnectionOnly, LoadToTable→DataModel, DataModel→LoadToTable, etc.).

Regression Tests Added

  • LoadTo_LoadedToTable_ThenConnectionOnly_RemovesTableAndConnection
  • LoadTo_LoadedToTable_ThenLoadToDataModel_RemovesTableAddsDataModel
  • LoadTo_LoadedToDataModel_ThenLoadToTable_RemovesDataModelAddsTable
  • LoadTo_LoadedToBoth_ThenConnectionOnly_RemovesBothDestinations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions