Skip to content

fix(search): rewrite numeric project: filters to project_id - #1621

Merged
betegon merged 3 commits into
mainfrom
fix/search-numeric-project-id
Sep 29, 2026
Merged

betegon merged 3 commits into
mainfrom
fix/search-numeric-project-id

Conversation

@betegon

@betegon betegon commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Issue search treats project as a slug. Agents paste Sentry's numeric project id into --query and get a 400 (CLI-FA). project_id is the numeric field.

sanitizeQuery now rewrites project:<digits> and all-numeric project:[id,id] to project_id, with a warning, same as the existing OR → in-list repair. Slugs (project:frontend), already-correct project_id:…, namespaced keys (bolt.project_id), quoted strings, and mixed in-lists are left alone.

Before / after

Command from CLI-FA:

sentry issue list --json -q "project:4511730126487632 environment:vercel-production"

Before — 400, ApiError, grouped in CLI-FA. The API rejects a numeric value on the slug field:

Error: Failed to fetch issues from 1 project(s): Failed to list issues: 400 Bad Request
  Endpoint: /api/0/organizations/…/issues/
  Invalid query: …

  Suggestions:
    • Check your --query syntax (Sentry search reference: …)
    • Try a shorter time range: --period 14d or --period 24h
    • Verify you have access to the target project: sentry project list <org>/

After — rewrite in sanitizeQuery, warn, run the query, exit 0:

⚠ `project` is the slug; numeric ids use project_id. Rewrote numeric project: filters. Running query: "project_id:4511730126487632 environment:vercel-production"

Stdout is the issue list JSON. Same rewrite for project:[4505521413357568,6442225] → project_id:[…].

Test plan

  • sanitizeQuery("project:4511730126487632 environment:vercel-production") → project_id:4511730126487632 environment:vercel-production
  • project:[4505521413357568,6442225] rewrites; project:[frontend,6442225] does not
  • project:frontend, project_id:123, bolt.project_id:70054175, message:"project:123" unchanged
  • From packages/cli: pnpm exec vitest run test/lib/search-query.test.ts test/lib/search-query.property.test.ts

Issue search treats project as a slug, so agents that paste project:<id>
hit a 400 (CLI-FA). Same auto-repair path as OR→in-list: rewrite digits
to project_id, leave slugs and namespaced keys alone.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Sep 29, 2026 12:35pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Sep 29, 2026 12:35pm UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – sentry-local September 22, 2026 14:09 Inactive
@betegon
betegon marked this pull request as ready for review September 22, 2026 14:11
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Sep 22, 2026
Comment thread packages/cli/src/lib/search-query.ts
## Summary

Follow-up to #1621. `sanitizeQuery` warned `Running query:` after the
numeric `project:` rewrite, then again after OR/AND. Combined input
logged an intermediate that never ran.

All rewrites now finish first. One warning: reasons on the first line,
`Running query:` on the second, quoting the query that is actually sent.
Same for a failed OR: no `Running query:` before the `ValidationError`.

Stacked on #1621 — merge that first.

### Before / after

```bash
sentry issue list --json -q "project:123 OR project:456"
```

**Before** — two warnings, first one is a lie:

```text
⚠ `project` is the slug; numeric ids use project_id. Rewrote numeric project: filters. Running query: "project_id:123 OR project_id:456"
⚠ Rewrote OR using in-list syntax: key:[val1,val2]. Running query: "project_id:[123,456]"
```

**After** — one warning, final query on its own line:

```text
⚠ `project` is the slug; numeric ids use project_id. Rewrote numeric project: filters. Rewrote OR using in-list syntax: key:[val1,val2].
  Running query: "project_id:[123,456]"
```

## Test plan

- [ ] `project:123 OR project:456` → `project_id:[123,456]`, one warn,
`Running query:` on the second line
- [ ] `project:123 AND is:unresolved` → `project_id:123 is:unresolved`,
same shape
- [ ] `level:error OR assigned:me` throws with no `Running query:`
- [ ] From `packages/cli`: `pnpm exec vitest run
test/lib/search-query.test.ts test/lib/search-query.warn.test.ts`

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread packages/cli/src/lib/search-query.ts
If project:<digits> was rewritten but the PEG parse still failed, the
rewritten string went to the API with no warning, and the 400 quoted a
project_id the user never typed. Compute notes before the parse and
warn in the passthrough path too. Logging there drains the silent
catch, so drop its grandfathered biome-ignore.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel
vercel Bot temporarily deployed to Preview – sentry-local September 29, 2026 12:34 Inactive
@betegon
betegon merged commit 6f9d323 into main Sep 29, 2026
37 checks passed
@betegon
betegon deleted the fix/search-numeric-project-id branch September 29, 2026 12:48

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — ebb59c59 Deployed Sep 29, 2026 by vercel[bot]
Preview – sentry-local — ebb59c59 Deployed Sep 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant