Skip to content

fix(cli): validate --id range on gitt i list to match sibling commands#855

Open
plind-junior wants to merge 1 commit intoentrius:testfrom
plind-junior:fix/issues-list-validate-id
Open

fix(cli): validate --id range on gitt i list to match sibling commands#855
plind-junior wants to merge 1 commit intoentrius:testfrom
plind-junior:fix/issues-list-validate-id

Conversation

@plind-junior
Copy link
Copy Markdown
Contributor

@plind-junior plind-junior commented Apr 29, 2026

Summary

gitt i list --id <N> accepted 0, negative numbers, and out-of-u32-range values and passed them straight through to on-chain lookup, returning a misleading "Issue N not found on-chain" message. Every sibling command using the same issue_id semantics (i submissions, vote solution, vote cancel) already rejects these inputs via validate_issue_id and emits a structured bad_parameter error. view.py:issues_list was the only outlier.

Closes the gap left by #210 / PR #211, which prescribed this validation across the CLI but listed only mutations.py / vote.py / admin.pyview.py was outside that scope.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other

Reproduction (before this PR)

$ gitt i submissions --id 0
✗ id must be between 1 and 999999 (got 0)              # ✅ rejected at input

$ gitt vote solution 0 5Hxxx... 5Hyyy... 1
✗ id must be between 1 and 999999 (got 0)              # ✅ rejected at input

$ gitt i list --id 0
Network: finney • Contract: ...
✗ Issue 0 not found on-chain.                          # ❌ silently did an on-chain query

$ gitt i list --id -1
✗ Issue -1 not found on-chain.                         # ❌ negative passed through

$ gitt i list --id 99999999999999
✗ Issue 99999999999999 not found on-chain.             # ❌ way out of u32 range, also passed through

Verified on upstream/test HEAD d8ba803.

After

$ gitt i list --id 0
✗ id must be between 1 and 999999 (got 0)              # ✅ matches submissions / vote

$ gitt i list --id 0 --json
{"success": false, "error": {"type": "bad_parameter", "message": "id must be between 1 and 999999 (got 0)"}}

$ gitt i list --id 1                                   # valid IDs unaffected
Network: finney • Contract: ...
✗ Issue 1 not found on-chain.                          # PR #335's structured not-found path preserved

$ gitt i list                                          # no --id, list-all path unchanged

Why this isn't a duplicate

Implementation

gittensor/cli/issue_commands/view.py:issues_list:

from .helpers import (
    ...
    validate_issue_id,
    ...
)

def issues_list(issue_id: int, ...):
    if issue_id is not None:
        try:
            validate_issue_id(issue_id, 'id')
        except click.BadParameter as e:
            handle_exception(as_json, str(e), 'bad_parameter')
    contract_addr, ws_endpoint, network_name = _resolve_contract_and_network(...)
    ...

Mirrors the existing pattern at submissions.py:57-60. Single gate at function entry; no new helpers, no new constants.

Testing

tests/cli/test_issues_list_json.py — 7 new parametric cases plus the 2 existing PR #335 regression tests:

Case Mode Asserts
--id 0, -1, 1000000, 99999999999999 human exit non-zero, "between 1 and 999999" in stderr, no contract read (mock not called)
--id 0, -1, 1000000 --json exit non-zero, structured {success: false, error: {type: bad_parameter, ...}}, no contract read
--id 999 (valid, missing) both PR #335's structured not_found path still fires (regression-locked)
$ pytest tests/cli/test_issues_list_json.py -v
9 passed in 0.08s

$ pytest tests/ -q --ignore=tests/test_synapses.py
659 passed, 2 warnings in 2.98s

Ruff lint + format clean on view.py and the test file.

Scope

  • 2 files changed, +34/-0 lines.
  • No API changes, no new dependencies, no behavior change for valid IDs or for the list-all path.
  • Aligns i list --id with i submissions --id, vote solution, vote cancel, and i register --id.

Related

Fixes #854

Labels

bug

`gitt i list --id <N>` accepted 0, negative, and out-of-u32-range values
and passed them through to on-chain lookup, returning "Issue N not found
on-chain". Sibling commands (`i submissions`, `vote solution`, `vote
cancel`) already reject these via validate_issue_id and emit a
structured "bad_parameter" error.

Apply the same gate in issues_list before _resolve_contract_and_network
so invalid IDs short-circuit without an RPC round-trip. JSON mode goes
through handle_exception(..., 'bad_parameter') for parity with
submissions; human mode prints the standard click message and exits
non-zero. PR entrius#335's structured not-found path is preserved for valid
IDs that simply don't exist on-chain.

Issue entrius#210 prescribed this validation across the CLI but listed only
mutations.py / vote.py / admin.py — view.py was outside that file scope
and was missed by PR entrius#211.
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] gitt i list --id accepts 0, negative, and out-of-range values

1 participant