Skip to content

fix: allow org switch by ID when org not in paginated list#2000

Merged
jlaneve merged 4 commits intomainfrom
fix/org-switch-pagination-fallback
Mar 2, 2026
Merged

fix: allow org switch by ID when org not in paginated list#2000
jlaneve merged 4 commits intomainfrom
fix/org-switch-pagination-fallback

Conversation

@jlaneve
Copy link
Contributor

@jlaneve jlaneve commented Jan 21, 2026

Summary

  • Fixes an issue where users with access to more than 100 organizations couldn't switch to orgs not appearing in the first page of results
  • Adds explicit pagination limit (100) to ListOrganizations
  • Adds new GetOrganization function to fetch an org directly by ID
  • Adds fallback in Switch to try fetching by ID when org isn't found in the list

Test plan

  • Unit tests pass (go test ./cloud/organization/...)
  • New test case added for the fallback scenario

🤖 Generated with Claude Code

When a user has access to more than 100 organizations, the target org
may not appear in the paginated list returned by ListOrganizations.
This change adds a fallback that attempts to fetch the organization
directly by ID if it's not found in the list.

- Add explicit limit of 100 to ListOrganizations
- Add new GetOrganization function to fetch org by ID
- Add fallback in Switch to try GetOrganization when org not in list

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
targetOrg = &or[i]
}
}
// If not found in list, try to get org by ID directly
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unfortunate that we have this ambiguous value that could be a name or an ID. I'd prefer if we could deal with this more systematically than a hail mary get org call if the first page of list orgs doesn't produce it. Can we look at the value and if it is a CUID then we do a get org call, otherwise we paginate through list orgs responses until we find it? Then we avoid unnecessary lookups, and if we don't find it we know it is really not there instead of maybe being on another page.

Replace the blind GetOrganization fallback with a three-way dispatch:
- CUID input → direct GetOrganization (1 API call)
- Name input → paginate through all ListOrganizations pages
- Empty input → interactive selection (unchanged)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jlaneve jlaneve requested a review from a team as a code owner March 2, 2026 15:58
jlaneve and others added 2 commits March 2, 2026 11:02
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The mocks were using exact param matching with empty
ListOrganizationsParams{}, but ListOrganizations always passes
Limit=100. This was a pre-existing issue. Switch to mock.Anything.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coveralls-official
Copy link

Pull Request Test Coverage Report for Build 83f93662-5764-4d4f-8ddf-7690b53e6365

Details

  • 48 of 55 (87.27%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.04%) to 33.188%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cloud/organization/organization.go 48 55 87.27%
Files with Coverage Reduction New Missed Lines %
cloud/organization/organization.go 1 88.1%
Totals Coverage Status
Change from base Build 63595748-3be8-42e5-8f39-9a30d684e069: 0.04%
Covered Lines: 20904
Relevant Lines: 62986

💛 - Coveralls

@jlaneve jlaneve merged commit 87fc21e into main Mar 2, 2026
5 of 6 checks passed
@jlaneve jlaneve deleted the fix/org-switch-pagination-fallback branch March 2, 2026 19:09
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.

2 participants