Skip to content

Fix/3788 always register profile workspace cli#3856

Open
ugbotueferhire wants to merge 2 commits intodlt-hub:develfrom
ugbotueferhire:fix/3788-always-register-profile-workspace-cli
Open

Fix/3788 always register profile workspace cli#3856
ugbotueferhire wants to merge 2 commits intodlt-hub:develfrom
ugbotueferhire:fix/3788-always-register-profile-workspace-cli

Conversation

@ugbotueferhire
Copy link
Copy Markdown

[Fix] – Always register dlt profile and dlt workspace CLI commands

Closes #3788

Description

Context:
The dlt profile and dlt workspace CLI commands were completely invisible when no .dlt/.workspace marker file existed. The plugin hooks plug_cli_profile() and plug_cli_workspace() in dlt._workspace.cli._plugins returned None when is_workspace_active() was False. Since pluggy silently filters None from hook results, argparse never learned these commands existed — they were absent from dlt --help and returned "invalid choice" when invoked directly. This broke discoverability for users, AI agents, and documentation references to dlt profile <name> pin.

Approach:
Added lightweight placeholder command classes that are registered unconditionally, following the same graceful-degradation pattern used by DeployCommand.execute() (which prints guidance when pipdeptree/cron_descriptor are missing rather than hiding the command):

  • _ProfilePlaceholder added to dlt/_workspace/cli/commands.py — stands in for ProfileCommand when workspace context is inactive. Accepts any arguments via nargs="*" and prints actionable setup instructions on execute.
  • _WorkspacePlaceholder added to dlt/_workspace/cli/commands.py — identical pattern for WorkspaceCommand.
  • plug_cli_profile() in dlt/_workspace/cli/_plugins.py — returns _ProfilePlaceholder instead of None when workspace is inactive.
  • plug_cli_workspace() in dlt/_workspace/cli/_plugins.py — returns _WorkspacePlaceholder instead of None when workspace is inactive.

No changes to the SupportsCliCommand protocol, the argparse wiring in _dlt.py, or any other command. When .dlt/.workspace exists, the real commands are returned exactly as before.

Impact:

  • Functionality: dlt profile and dlt workspace are now always visible in dlt --help and print clear setup instructions when invoked outside a workspace context, instead of silently vanishing.
  • Developer Experience: Users and AI agents that read docs referencing dlt profile <name> pin now get an actionable error with exact remediation steps (mkdir -p .dlt && touch .dlt/.workspace) instead of a cryptic argparse rejection.
  • Robustness: Zero regression risk — when workspace is active, the original ProfileCommand and WorkspaceCommand are still returned by the plugin hooks. The placeholder classes are only used in the fallback path.

Visual Proof

image

Tests

  • New tests added
  • Existing tests unaffected (no regressions)

Manual verification performed:

  • dlt --help lists both profile and workspace without .dlt/.workspace
  • dlt profile list prints setup instructions and exits non-zero ✅
  • dlt workspace info prints setup instructions and exits non-zero ✅
  • With .dlt/.workspace present, real ProfileCommand / WorkspaceCommand execute normally ✅

When workspace context is not active, dlt profile and dlt workspace were completely absent from the CLI because the plugin hooks returned None. This adds placeholder command classes that print actionable setup instructions instead of silently vanishing.
@ugbotueferhire
Copy link
Copy Markdown
Author

Hi @anuunchin , whenever you have a moment, could you please take a look at this PR for a review? Let me know if you need any changes. Thanks!

@ugbotueferhire
Copy link
Copy Markdown
Author

Hey @anuunchin, following up on this PR. Pretty low-risk change, would appreciate a review when you have bandwidth or if you could assign someone to this, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dlt profile command should always be available with guidance when workspace is not initialized

1 participant