This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Repository navigation
fix(api): use numeric project ID to avoid "not actively selected" error - #312
Merged
Merged
Conversation
Store the numeric project ID alongside the slug in the cache so downstream API calls can use the `project` query param instead of `project:<slug>` search syntax. Bump schema version to 7 with migration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`sentry issue list sentry/sentry` failed because `project:slug` in the search query only works for "actively selected" projects. When we have the numeric project ID, use the `project` query param (Array<number>) instead, which selects the project directly. - Add `projectId` to `ResolvedTarget` and populate it from all resolution paths (explicit, DSN, cache, directory inference) - `listIssuesPaginated` uses `project: [id]` query param when available, falls back to `project:slug` search syntax otherwise - Thread `projectId` through `listIssuesAllPages` and `fetchIssuesForTarget` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that when projectId is provided, the `project` query param is used and `project:slug` is omitted from the search query. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Api
Formatters
Other
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 2291 passed | Total: 2291 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 82.47%. Project has 3241 uncovered lines. Files with missing lines (4)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 80.08% 80.14% +0.06%
==========================================
Files 120 120 —
Lines 16232 16316 +84
Branches 0 0 —
==========================================
+ Hits 12999 13075 +76
- Misses 3233 3241 +8
- Partials 0 0 —Generated by Codecov Action |
…warnings - Replace nested ternary with if-statement in listIssuesPaginated - Extract fetchProjectId helper to reduce resolveAllTargets complexity - Use numeric separators (12_345) in test literals Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…projects fetchProjectId previously swallowed all errors silently, causing confusing downstream API errors when users typed a wrong project slug or lacked permissions. Now throws ResolutionError on 404 and re-throws AuthError, while still returning undefined for transient failures. Partial-failure messages now name the specific projects that failed (e.g. "Failed to fetch issues from org/proj-a") instead of just showing a count, both in human-readable stderr and JSON error output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The pattern `Number(x.id) || undefined` appeared 7 times and `cached.projectId ? Number(cached.projectId) : undefined` appeared 3 times across resolve-target.ts and list.ts. Extract a shared `toNumericId` helper to replace all 10 occurrences. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix 10 lint errors (trailing commas, line length, import ordering, Response.json) and 2 test failures caused by fetchProjectId requiring auth/region mocks when CLI flags are passed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…re project field Improve patch coverage for PR #312 by adding tests for new functions and enhancing existing assertions on error output format. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
betegon
marked this pull request as ready for review
March 2, 2026 11:12
Remove fetchProjectId from shared resolveAllTargets/resolveOrgAndProject (Point 1), enrich missing projectId in issue list's auto-detect path so env-var and config-default targets also get numeric IDs (Point 2), fix toNumericId(0) returning undefined via explicit Number.isFinite check (Point 3), and update tests accordingly (Point 4). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
BYK
added a commit
that referenced
this pull request
Mar 2, 2026
- toNumericId: accept null, use Number.isInteger + n > 0 (was falsy-check) - Remove fetchProjectId from resolveAllTargets/resolveOrgAndProject shared paths (dead code that added network calls to non-issue-list commands) - Enrich env-var/config-default auto-detect targets in issue list using getProject directly with silent fallback to slug-based querying - Fix test: spy on getProject in cursor-accepted test to avoid hitting the preload fetch mock (removed 3 [TEST] Unexpected fetch call warnings)
- toNumericId: accept null, use Number.isInteger + n > 0 (was falsy-check) - Remove fetchProjectId from resolveAllTargets/resolveOrgAndProject shared paths (dead code that added network calls to non-issue-list commands) - Enrich env-var/config-default auto-detect targets in issue list using getProject directly with silent fallback to slug-based querying - Fix test: spy on getProject in cursor-accepted test to avoid hitting the preload fetch mock (removed 3 [TEST] Unexpected fetch call warnings)
BYK
approved these changes
Mar 2, 2026
5 tasks
BYK
pushed a commit
that referenced
this pull request
Jul 30, 2026
`sentry log list <org>/<project>` (and `log view`) returned an empty result — `No logs found in the last 30d` — for projects that aren't actively selected in the org, even when the Events API had logs for them. The log API scoped a slug target only via `project:<slug>` search syntax, which the Events endpoint matches only when that project is actively selected. This resolves the slug to its numeric project ID and passes `project: [id]` on the request instead (mirroring the issues fix in #312), falling back to `project:<slug>` scoping only when no ID is available. Both `log list` and `log view` are covered. The same naively-concatenated `project:<slug> <user-query>` also surfaces as `400 Bad Request` from the Events API whenever the user passes `--query` against a slug-scoped project — root cause is identical (slug scoping in query string instead of via `project=` param). Tracking issue: #1319. ## Sentry issues resolved - [CLI-R2](https://sentry.io/issues/CLI-R2/) — `ApiError: Failed to list logs: 400 Bad Request` — 316 events (every event had the malformed `query=project:<slug> <user-query>` pattern) - [CLI-1TQ](https://sentry.io/issues/CLI-1TQ/) — same title — 16 events (same pattern confirmed across all sampled events) ## Testing `bun run typecheck`, biome lint on changed files, and the log command + log API test suites (`test/commands/log/*`, `test/lib/api/logs.test.ts`) — all green. Added tests asserting the `project` param is used when an ID is available and that scoping falls back to `project:<slug>` otherwise. Closes #1317 Closes #1319 <!-- ## Plan Root cause: in `src/lib/api/logs.ts`, `listLogs()` and `getLogsBatch()` scope a slug target only via `project:<slug>` in the search query and never send the numeric `project=` param. The Events (ourlogs) API only matches `project:<slug>` when the project is actively selected, so a plain slug returns empty `data: []`. Changes: - `src/lib/api/logs.ts`: add `projectId` to options, `resolveNumericProjectId` helper, send `project: [id]` when available else fall back to `project:<slug>`. - `src/lib/resolve-target.ts`: new `resolveLogProjectId` (cache-first, tolerates transient failures, re-throws ResolutionError). - `src/commands/log/list.ts` + `view.ts`: resolve slug→id and thread it through. - Tests updated/added accordingly. `listTraceLogs` is intentionally untouched — it's org-scoped and unaffected. --> --------- Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>
4 of 5 tasks
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
sentry issue list sentry/sentryfailed with "Project(s) sentry do not exist or are not actively selected" becauselistIssuesPaginatedpassed the project asproject:sentryin the search query string. The Sentry Issues API only searches within "actively selected" projects for that syntax.When we have the numeric project ID, we now use the
projectquery param (Array<number>) instead, which selects the project directly and bypasses the "actively selected" requirement.Changes
Thread numeric
projectIdthroughResolvedTarget→ API calls:project_cacheschema: addproject_idcolumn (schema v7) so cached lookups also return the IDResolvedTarget: addprojectId?: number, populated from all resolution paths (explicit targets viagetProject, DSN detection, cache hits, directory inference)listIssuesPaginated: whenprojectIdis provided, useproject: [id]query param instead ofproject:<slug>search syntax; fall back to slug when ID is unavailablelistIssuesAllPages/fetchIssuesForTarget: passprojectIdthroughFor explicit targets (
sentry issue list org/project), thegetProjectcall also serves as early validation — typos now fail with a clear 404 instead of a confusing "not actively selected" error from the issues endpoint.Test plan
projectIdinlistIssuesPaginated(3 tests)sentry issue list sentry/sentry -n 5now returns issues (was failing)