Skip to content

fix(cli): scope 'image search -p' to the project#486

Merged
digaobarbosa merged 5 commits into
mainfrom
digao/fix-image-search-project-scope
Jun 2, 2026
Merged

fix(cli): scope 'image search -p' to the project#486
digaobarbosa merged 5 commits into
mainfrom
digao/fix-image-search-project-scope

Conversation

@digaobarbosa
Copy link
Copy Markdown
Contributor

@digaobarbosa digaobarbosa commented May 25, 2026

Description

roboflow image search "<query>" -p <project> silently ignored -p and returned workspace-wide results — so IDs could come from other projects, and a follow-up image get -p <project> <id> would 404.

Root cause: _handle_search built its args with project=... but never used it — it called rfapi.workspace_search with only the raw query, so nothing scoped the result to the project.

image search Before (bug) After (fix)
"*" -p penguin-finder 117,275 (whole workspace) 26,804 (project)
"class:penguin" -p penguin-finder 646 (workspace) 515 (project)

Type of change

  • Bug fix

How has this change been tested?

  • Live: ran the commands above against staging and confirmed scoped totals.
  • Unit: strengthened test_search to assert the scoped query project:proj tag:test; added test_search_without_project_is_unscoped. Full suite passes (python -m unittest), ruff check/format clean.

Will the change affect Universe?

No.

Any specific deployment considerations

N/A (Python SDK / CLI package).

Docs

  • Docs updated? N/A

The -p/--project flag was silently ignored: _handle_search passed the
project nowhere, so every search returned workspace-wide results.

The search/v1 endpoint only honors a project filter expressed inside the
RoboQL query (project:<slug>, which the API resolves to a project id) —
body-level project/dataset params are ignored. Prepend project:<slug> to
the user's query with a leading space (implicit AND) so it stays
compatible with free-text/semantic queries; an explicit 'AND (...)'
wrapper 500s on free text.
@digaobarbosa digaobarbosa self-assigned this May 25, 2026
@digaobarbosa digaobarbosa requested a review from a team May 25, 2026 17:24
`image search -p <proj> --export` silently dropped the export: the `if
project` branch ran before `elif export`, so it routed to a plain
project-scoped search and ignored --export and all export flags.

Check export first and pass -p through as the export `dataset` (project
slug) body param, which is how search/export natively scopes. Plain `-p`
search is unchanged (still injects a `project:<slug>` RoboQL filter).

Also clarify the -p help text ("Project slug to scope results") since the
search/v1 endpoint scopes by slug, not by an ignored body param.

Add regression tests for both routes.
_search built the SDK client with roboflow.Roboflow() and never passed
the CLI's --api-key, so the export path (and the hidden top-level search
command) ignored an explicitly supplied key and required saved/env creds.
This broke the now-functional `image search -p ... --export` in CI and
agent workflows that pass the key directly.

Pass api_key=args.api_key; Roboflow() still falls back to saved/env creds
when it is None, so the default-login flow is unchanged.

Add a regression test asserting Roboflow receives the root --api-key.
@digaobarbosa digaobarbosa merged commit a7f4bdd into main Jun 2, 2026
15 checks passed
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