Repository navigation
fix(droplets): resolve all-numeric Droplet names in get - #2158
Open
aniruddhaadak80 wants to merge 2 commits into
Open
aniruddhaadak80 wants to merge 2 commits into
aniruddhaadak80 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, becausematchDropletsshort-circuited onallInt()and never consulted the name lookup.This PR resolves the identifier as follows:
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;Only
RunDropletGetis changed. The sharedmatchDropletshelper used bydelete,tag, anduntagis untouched, so those commands keep their current batching and permission behavior.Related Issue
Fixes #1087
Type of Change
Changes Made
getDropletByIdentifier,getDropletByName, andisDropletNotFoundhelpers incommands/droplets.go.RunDropletGetnow uses the new resolver; ID-first lookup means no extra list request in the common case.commands/droplets_test.gofor 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.go test ./commands -run 'TestDropletGet_Numeric' -count=1on unmodifiedupstream/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=1after 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
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 inTestPackHarborTaskRejects/too_many_files(harbor pack file traversal on Windows).TestRunHarborJobDownloadfails on this Windows host withrename ... 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.goand 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.