Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

fix(api): use numeric project ID to avoid "not actively selected" error - #312

Merged
BYK merged 11 commits into
mainfrom
fix/issue-list-project-id
Mar 2, 2026
Merged

BYK merged 11 commits into
mainfrom
fix/issue-list-project-id

Conversation

@betegon

@betegon betegon commented Mar 2, 2026

Copy link
Copy Markdown
Member

Summary

sentry issue list sentry/sentry failed with "Project(s) sentry do not exist or are not actively selected" because listIssuesPaginated passed the project as project:sentry in 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 project query param (Array<number>) instead, which selects the project directly and bypasses the "actively selected" requirement.

Changes

Thread numeric projectId through ResolvedTarget → API calls:

  • project_cache schema: add project_id column (schema v7) so cached lookups also return the ID
  • ResolvedTarget: add projectId?: number, populated from all resolution paths (explicit targets via getProject, DSN detection, cache hits, directory inference)
  • listIssuesPaginated: when projectId is provided, use project: [id] query param instead of project:<slug> search syntax; fall back to slug when ID is unavailable
  • listIssuesAllPages / fetchIssuesForTarget: pass projectId through

For explicit targets (sentry issue list org/project), the getProject call 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

  • New unit tests for projectId in listIssuesPaginated (3 tests)
  • All existing tests pass (113 tests across api-client, resolve-target, schema)
  • Manual: sentry issue list sentry/sentry -n 5 now returns issues (was failing)

betegon and others added 3 commits March 2, 2026 10:53
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>
@github-actions

github-actions Bot commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (formatters) Render all terminal output as markdown by BYK in #297
  • (issue-list) Global limit with fair distribution, compound cursor, and richer progress by BYK in #306

Bug Fixes 🐛

Api

  • Use numeric project ID to avoid "not actively selected" error by betegon in #312
  • Use limit param for issues endpoint page size by BYK in #309
  • Auto-correct ':' to '=' in --field values with a warning by BYK in #302

Formatters

  • Expand streaming table to fill terminal width by betegon in #314
  • Fix HTML entities and escaped underscores in table output by betegon in #313

Other

  • (ci) Generate JUnit XML to silence codecov-action warnings by BYK in #300
  • (nightly) Push to GHCR from artifacts dir so layer titles are bare filenames by BYK in #301
  • (test) Handle 0/-0 in getComparator anti-symmetry property test by BYK in #308

Internal Changes 🔧

  • (api) Wire listIssuesPaginated through @sentry/api SDK for type safety by BYK in #310

🤖 This preview updates automatically when you update the PR.

@github-actions

github-actions Bot commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ 2291 passed | Total: 2291 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +19
Passed Tests 📈 +19
Failed Tests —
Skipped Tests —

All tests are passing successfully.

✅ Patch coverage is 82.47%. Project has 3241 uncovered lines.
✅ Project coverage is 80.14%. Comparing base (base) to head (head).

Files with missing lines (4)
File Patch % Lines
resolve-target.ts 53.44% ⚠️ 291 Missing
api-client.ts 72.96% ⚠️ 242 Missing
list.ts 87.13% ⚠️ 96 Missing
schema.ts 93.07% ⚠️ 33 Missing
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

betegon and others added 5 commits March 2, 2026 11:03
…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
betegon marked this pull request as ready for review March 2, 2026 11:12
@betegon
betegon requested review from BYK and MathurAditya724 March 2, 2026 11:16
Comment thread src/lib/resolve-target.ts Resolved
Comment thread src/lib/resolve-target.ts Resolved
betegon and others added 2 commits March 2, 2026 14:39
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>

@cursor cursor Bot 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.

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.

Comment thread src/commands/issue/list.ts Resolved
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
BYK merged commit 63d397e into main Mar 2, 2026
20 checks passed
@BYK
BYK deleted the fix/issue-list-project-id branch March 2, 2026 14:34
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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants