Skip to content

fix(droplets): resolve all-numeric Droplet names in get - #2158

Open
aniruddhaadak80 wants to merge 2 commits into
digitalocean:mainfrom
aniruddhaadak80:fix/droplet-get-numeric-name
Open

aniruddhaadak80 wants to merge 2 commits into
digitalocean:mainfrom
aniruddhaadak80:fix/droplet-get-numeric-name

Conversation

@aniruddhaadak80

Copy link
Copy Markdown

Description

doctl compute droplet get <identifier> documented <droplet-id|droplet-name>, but a Droplet whose name is entirely numeric was always treated as an ID. The API returned 404 even though the Droplet existed, because matchDroplets short-circuited on allInt() and never consulted the name lookup.

This PR resolves the identifier as follows:

  • non-numeric identifier: unchanged — look up by name in the Droplet list, then fetch by ID;
  • numeric identifier: try Get(id) first (preserves the fast path and all existing ID behavior); on an HTTP 404, look the identifier up as a name and fetch the matching Droplet;
  • if the identifier is neither a valid ID nor a known name, the original API 404 is returned rather than a misleading "name not found" message;
  • ambiguous names and non-404 errors behave exactly as before.

Only RunDropletGet is changed. The shared matchDroplets helper used by delete, tag, and untag is untouched, so those commands keep their current batching and permission behavior.

Related Issue

Fixes #1087

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change
  • Documentation update
  • Refactoring / Code cleanup
  • Performance improvement
  • CI/CD changes

Changes Made

  • Added getDropletByIdentifier, getDropletByName, and isDropletNotFound helpers in commands/droplets.go.
  • RunDropletGet now uses the new resolver; ID-first lookup means no extra list request in the common case.
  • Added regression tests in commands/droplets_test.go for a numeric name, a non-404 API error on a numeric ID, and a numeric identifier that is neither ID nor name.

Testing

Run from an isolated worktree based on upstream/main:

  • gofmt -w commands/droplets.go commands/droplets_test.go — clean.
  • Pre-fix proof: go test ./commands -run 'TestDropletGet_Numeric' -count=1 on unmodified upstream/main — FAIL (missing call(s) to ...List(), missing call(s) to ...Get(42)), i.e. the new test reproduces the bug.
  • go test ./commands -run 'TestDropletGet|TestDropletsTag|TestDropletDelete' -count=1 — ok github.com/digitalocean/doctl/commands 1.701s.
  • go test ./commands -run 'TestDropletGet' -count=1 after the final refactor — ok github.com/digitalocean/doctl/commands 0.515s.
  • go test ./commands -count=1 -skip 'TestPackHarborTaskRejects|TestRunHarborJobDownload' -timeout 15m — ok github.com/digitalocean/doctl/commands 53.547s.
  • go vet ./commands — no output, exit 0.
  • go build -o doctl-1087.exe ./cmd/doctl — exit 0, 54,524,416-byte binary (removed afterwards).
  • git diff --check — no whitespace errors.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation (no documented behavior changes; the command already advertises name support)
  • My changes generate no new warnings or errors
  • New and existing unit tests pass locally with my changes (see limitations)

Additional Context

Limitations / known environment issues, both unrelated to this change and reproducible on the unmodified base:

  • go test ./commands -count=1 (no skip) times out after 10m in TestPackHarborTaskRejects/too_many_files (harbor pack file traversal on Windows).
  • TestRunHarborJobDownload fails on this Windows host with rename ... The process cannot access the file because it is being used by another process (temp-file handling in the harbor download test).

Both tests are in harbor_pack_test.go / harbor_test.go and do not touch Droplet code; they were skipped only for the broad run above. The full targeted Droplet and tag suites pass.

AI disclosure: this patch and its tests were prepared with AI assistance (OpenCode agent), then reviewed and verified locally as described above.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

Get droplet by name does not work in the case your name is a number

2 participants