Skip to content

fix: convert object get --filter values to the type the filter expects - #1418

Open
lancamat1 wants to merge 4 commits into
stablefrom
ai-bug-pipeline-1417-filter-values-sent-as-strings
Open

lancamat1 wants to merge 4 commits into
stablefrom
ai-bug-pipeline-1417-filter-values-sent-as-strings

Conversation

@lancamat1

@lancamat1 lancamat1 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

infrahubctl object get --filter sends every filter value to Infrahub as a string. Filters whose GraphQL argument is not a string fail, for example --filter interfaces__isnull=true returns Boolean cannot represent a non boolean value: "true". The same filter works through client.filters(..., interfaces__isnull=True).

The goal is that --filter sends boolean and integer values with the type the filter expects, so these filters work from the CLI the same way they work from the SDK.

Non-goals:

  • peer attribute filters (<relationship>__<peer_attribute>__value) are still sent as strings, typing them would need the peer schema as well
  • __values list filters, --filter has no list syntax today
  • partial_match, which is a bool keyword of client.filters() and still receives a string when passed through --filter

Closes #1417

What changed

  • __isnull, __is_visible and __is_protected filters are sent as booleans (true, false, yes, no, case insensitive)
  • <attribute>__value filters on Boolean or Checkbox attributes are sent as booleans, and on Number or NumberPool attributes as integers, based on the node schema object get already loads
  • all other values stay strings, so name__value=123 on a Text attribute is still sent as "123"
  • a value that cannot be converted (for example interfaces__isnull=maybe) now fails in the CLI with a message naming the filter and the expected type, instead of a 500 from the server

parse_filter_args() gets an optional schema argument, so existing callers keep working. The true/false keyword map is now shared with --set parsing, the --set behaviour does not change.

How to review

The change is in infrahub_sdk/ctl/parsers.py, the one-line call site change is in infrahub_sdk/ctl/object/get.py.

The part I would like a second opinion on is the decision to type values from the filter suffix and the attribute kind, instead of running _coerce_value() on every value like --set does. Coercing everything would turn name__value=123 into an integer and break String filters the opposite way.

How to test

uv run pytest tests/unit/ctl/object/test_get.py tests/unit/ctl/test_parsers.py

Locally invoke format, invoke lint-code and invoke docs-validate pass. I have not run the fixed command against a live Infrahub instance, the tests check the values passed to client.filters().

Impact & rollout

  • Backward compatibility: no breaking change. Filters that worked before still send the same values, only filters that the server rejected before now send typed values. A --filter value that cannot be converted for a boolean or integer filter now fails in the CLI instead of on the server.

Checklist

  • Tests added/updated
  • Changelog entry added (uv run towncrier create ...)
  • External docs updated (if user-facing or ops-facing change), not needed, the --filter help text and the generated CLI docs do not change
  • Internal .md docs updated (internal knowledge and AI code tools knowledge), not needed

Summary by cubic

Fixes infrahubctl object get --filter sending boolean and integer filter values as strings, which made filters like interfaces__isnull=true fail with a GraphQL type error. Values for __isnull, __is_visible, __is_protected, and __value filters on Boolean/Number attributes are now converted to the expected type based on the suffix and the node schema; all other values stay stringsesth.

Backward compatibility

  • No breaking change: filters that worked before still send the same values.
  • Values that cannot be converted now fail in the CLI with a clear error naming the filter and expected type, instead of a 500 from the server.

Written for commit ce42823. Summary will update on new commits.

View guided diff Turn on auto-fix

…xpects

parse_filter_args() kept every value as a string, so boolean filters such
as <relationship>__isnull=true were sent as the GraphQL string "true" and
rejected by the server. Values for __isnull, __is_visible and __is_protected
filters now become booleans, and <attribute>__value filters on Boolean or
Number attributes become booleans or integers, based on the node schema.
Other values stay strings.

Fixes #1417
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: ce42823
Status: ✅  Deploy successful!
Preview URL: https://a363f349.infrahub-sdk-python.pages.dev
Branch Preview URL: https://ai-bug-pipeline-1417-filter.infrahub-sdk-python.pages.dev

View logs

@lancamat1 lancamat1 added the type/bug Something isn't working as expected label Oct 13, 2026
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable    #1418      +/-   ##
==========================================
+ Coverage   85.06%   85.11%   +0.04%     
==========================================
  Files         148      148              
  Lines       13303    13312       +9     
  Branches     1960     1958       -2     
==========================================
+ Hits        11316    11330      +14     
+ Misses       1422     1418       -4     
+ Partials      565      564       -1     
Flag Coverage Δ
integration-tests 38.70% <42.85%> (-0.08%) ⬇️
python-3.10 58.07% <100.00%> (+0.17%) ⬆️
python-3.11 58.07% <100.00%> (+0.18%) ⬆️
python-3.12 58.07% <100.00%> (+0.18%) ⬆️
python-3.13 58.07% <100.00%> (+0.17%) ⬆️
python-3.14 58.07% <100.00%> (+0.17%) ⬆️
python-filler-3.12 23.70% <0.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/object/get.py 86.48% <100.00%> (ø)
infrahub_sdk/ctl/parsers.py 95.34% <100.00%> (+2.49%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lancamat1
lancamat1 marked this pull request as ready for review October 14, 2026 12:30
@lancamat1
lancamat1 requested a review from a team as a code owner October 14, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: infrahubctl object get --filter sends boolean values as strings

1 participant