Skip to content

Remove raise_for_error from several methods#874

Merged
gmazoyer merged 1 commit intoinfrahub-developfrom
gma-20260317-infp380
Mar 17, 2026
Merged

Remove raise_for_error from several methods#874
gmazoyer merged 1 commit intoinfrahub-developfrom
gma-20260317-infp380

Conversation

@gmazoyer
Copy link
Copy Markdown
Contributor

@gmazoyer gmazoyer commented Mar 17, 2026

Why

The raise_for_error parameter was deprecated in v1.15.0 (#508) with a DeprecationWarning. It is now time to fully remove it to clean up the public API.

What changed

  • Removed raise_for_error parameter from both async (InfrahubClient) and sync (InfrahubClientSync) versions of:
    • execute_graphql
    • query_gql_query
    • get_diff_summary
    • allocate_next_ip_address
    • allocate_next_ip_prefix
  • resp.raise_for_status() is now always called in execute_graphql and query_gql_query (previously conditional on raise_for_error).
  • Removed raise_for_error_deprecation_warning helper.
  • Simplified overloads.
  • Updated internal callers, removed raise_for_error=True.

How to review

  • The diff is large but almost entirely mechanical removal of the parameter, its deprecation warning, its conditional usage, and redundant overloads.

How to test

uv run invoke format lint-code
uv run pytest tests/unit/ -q

Impact & rollout

  • Backward compatibility: any code passing raise_for_error=... to these methods will get a TypeError. This was deprecated since v1.15.0 with a DeprecationWarning.

Checklist

  • Tests added/updated
  • Changelog entry added
  • External docs updated

Summary by CodeRabbit

Breaking Changes

  • Removed raise_for_error parameter from client methods
  • HTTP/GraphQL errors now consistently raise exceptions without suppression
  • Allocation methods may return None in some cases
  • Method overloads consolidated for simplified API

This parameter has been deprecated for a while and should not be used
anymore.
@gmazoyer gmazoyer requested a review from a team as a code owner March 17, 2026 10:42
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Mar 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 17, 2026

Walkthrough

The pull request removes the deprecated raise_for_error parameter from five SDK client methods: execute_graphql, query_gql_query, get_diff_summary, allocate_next_ip_address, and allocate_next_ip_prefix. HTTP errors are now unconditionally raised via resp.raise_for_status(). Related method overloads have been consolidated, and the raise_for_error_deprecation_warning helper function has been removed. Return types for allocate_next_ip_address and allocate_next_ip_prefix now permit None. CLI utilities and documentation have been updated to reflect these changes.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.10% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removal of the raise_for_error parameter from multiple methods.
Description check ✅ Passed The description covers Why, What changed, How to review, How to test, Impact & rollout, and Checklist sections with sufficient detail and completeness.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/client.py 75.00% 1 Missing ⚠️
@@                 Coverage Diff                  @@
##           infrahub-develop     #874      +/-   ##
====================================================
+ Coverage             80.62%   80.77%   +0.14%     
====================================================
  Files                   119      119              
  Lines                 10335    10311      -24     
  Branches               1550     1529      -21     
====================================================
- Hits                   8333     8329       -4     
+ Misses                 1475     1473       -2     
+ Partials                527      509      -18     
Flag Coverage Δ
integration-tests 40.29% <50.00%> (+0.22%) ⬆️
python-3.10 52.09% <75.00%> (+0.25%) ⬆️
python-3.11 52.09% <75.00%> (+0.27%) ⬆️
python-3.12 52.09% <75.00%> (+0.27%) ⬆️
python-3.13 52.08% <75.00%> (+0.23%) ⬆️
python-3.14 53.78% <75.00%> (+0.26%) ⬆️
python-filler-3.12 23.92% <0.00%> (-0.12%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/ctl/utils.py 68.53% <ø> (ø)
infrahub_sdk/ctl/validate.py 52.11% <ø> (ø)
infrahub_sdk/client.py 73.64% <75.00%> (+0.76%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
docs/docs/python-sdk/sdk_ref/infrahub_sdk/client.mdx (2)

225-245: ⚠️ Potential issue | 🟡 Minor

Document the default HTTP exceptions for execute_graphql().

raise_for_error is gone, so non-2xx responses are now part of the default contract, but the Raises section still only lists GraphQLError. Please update the source docstrings to mention the HTTP/auth exceptions callers now need to handle, then regenerate this reference.

Based on learnings, do not edit docs/python-sdk/sdk_ref/**/*.mdx files directly; regenerate with uv run invoke docs-generate.

Also applies to: 506-526

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/docs/python-sdk/sdk_ref/infrahub_sdk/client.mdx` around lines 225 - 245,
The docstring for execute_graphql() must be updated to document that non-2xx
HTTP responses and authentication errors can be raised (in addition to
GraphQLError); update the source function's docstring (execute_graphql in the
client class) to list HTTPError/RequestException (or your project's HTTP/auth
exception types) under Raises and describe when they occur, then regenerate the
SDK reference HTML/MDX by running the docs generation task (uv run invoke
docs-generate) rather than editing docs/python-sdk/sdk_ref/*.mdx directly; apply
the same docstring change to the other affected execute_graphql occurrences
mentioned.

290-323: ⚠️ Potential issue | 🟡 Minor

The allocation docblocks still describe non-optional returns.

These signatures now return ... | None, but the prose below still promises an InfrahubNode only, and the sync prefix block still refers to size instead of prefix_length. Please fix the source docstrings and regenerate so the narrative matches the API surface.

Based on learnings, do not edit docs/python-sdk/sdk_ref/**/*.mdx files directly; regenerate with uv run invoke docs-generate.

Also applies to: 328-361, 676-709, 714-747

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/docs/python-sdk/sdk_ref/infrahub_sdk/client.mdx` around lines 290 - 323,
The docstrings for allocate_next_ip_address (and the other affected allocation
methods) still describe a non-optional InfrahubNode return and reference a
"size" parameter in the sync prefix block even though the API signatures now
return Optional (e.g., SchemaType | None) and use prefix_length; update the
original Python docstrings for allocate_next_ip_address (and the other listed
allocator methods) to state the return may be None (InfrahubNode | None) and
replace any "size" mentions with "prefix_length" in the sync prefix
examples/descriptions, then regenerate the SDK docs (do NOT edit
docs/python-sdk/sdk_ref/**/*.mdx directly) by running `uv run invoke
docs-generate`.
infrahub_sdk/client.py (1)

945-965: ⚠️ Potential issue | 🔴 Critical

Re-raise unexpected HTTP status codes instead of silently replaying the request.

When an httpx.HTTPStatusError is raised with a status code outside {401, 403, 404}, the exception is caught but not re-raised. With retry_on_failure=True, the loop silently retries until max_retry_duration expires—dangerous for mutations since retries aren't guaranteed idempotent. With retries disabled, the failed response is treated as successful and passed to decode_json().

🔧 Minimal fix
             except httpx.HTTPStatusError as exc:
                 if exc.response.status_code in {401, 403}:
                     response = decode_json(response=exc.response)
                     errors = response.get("errors", [])
                     messages = [error.get("message") for error in errors]
                     raise AuthenticationError(" | ".join(messages)) from exc
                 if exc.response.status_code == 404:
                     raise URLNotFoundError(url=url) from exc
+                raise

Also applies to: line 1852–1872 (sync version)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/client.py` around lines 945 - 965, The HTTPStatusError except
block around the async request (the block handling resp = await self._post(...)
and httpx.HTTPStatusError as exc) only handles 401/403 and 404 but swallows all
other status codes, causing silent retries or treating failures as success;
update that except block to re-raise the original exc for any status codes not
explicitly handled (i.e., after handling 401/403 -> raise AuthenticationError
and 404 -> raise URLNotFoundError, add a final raise exc), and mirror the same
change in the sync equivalent (the similar except block around the non-async
_post call) so unexpected HTTP errors are not silently replayed or passed to
decode_json().
🧹 Nitpick comments (1)
changelog/+infp380.removed.md (1)

1-1: Call out the TypeError migration break explicitly.

The entry says the argument is gone, but not what existing callers will actually see. Adding a short note that passing raise_for_error now raises TypeError will make the upgrade impact much easier to spot.

✍️ Suggested wording
- Removed the deprecated `raise_for_error` argument from `execute_graphql`, `query_gql_query`, `get_diff_summary`, `allocate_next_ip_address`, and `allocate_next_ip_prefix` client methods. HTTP errors are now always raised via `resp.raise_for_status()`.
+ Removed the deprecated `raise_for_error` argument from `execute_graphql`, `query_gql_query`, `get_diff_summary`, `allocate_next_ip_address`, and `allocate_next_ip_prefix` client methods. HTTP errors are now always raised via `resp.raise_for_status()`. Passing `raise_for_error` to these methods now raises `TypeError`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@changelog/`+infp380.removed.md at line 1, Update the changelog entry to
explicitly note that callers who pass the removed raise_for_error argument will
now receive a TypeError; edit the sentence mentioning the removed argument for
execute_graphql, query_gql_query, get_diff_summary, allocate_next_ip_address,
and allocate_next_ip_prefix to add a short parenthetical or following sentence
like “Passing raise_for_error will now raise TypeError” so the migration break
is clear to readers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@docs/docs/python-sdk/sdk_ref/infrahub_sdk/client.mdx`:
- Around line 225-245: The docstring for execute_graphql() must be updated to
document that non-2xx HTTP responses and authentication errors can be raised (in
addition to GraphQLError); update the source function's docstring
(execute_graphql in the client class) to list HTTPError/RequestException (or
your project's HTTP/auth exception types) under Raises and describe when they
occur, then regenerate the SDK reference HTML/MDX by running the docs generation
task (uv run invoke docs-generate) rather than editing
docs/python-sdk/sdk_ref/*.mdx directly; apply the same docstring change to the
other affected execute_graphql occurrences mentioned.
- Around line 290-323: The docstrings for allocate_next_ip_address (and the
other affected allocation methods) still describe a non-optional InfrahubNode
return and reference a "size" parameter in the sync prefix block even though the
API signatures now return Optional (e.g., SchemaType | None) and use
prefix_length; update the original Python docstrings for
allocate_next_ip_address (and the other listed allocator methods) to state the
return may be None (InfrahubNode | None) and replace any "size" mentions with
"prefix_length" in the sync prefix examples/descriptions, then regenerate the
SDK docs (do NOT edit docs/python-sdk/sdk_ref/**/*.mdx directly) by running `uv
run invoke docs-generate`.

In `@infrahub_sdk/client.py`:
- Around line 945-965: The HTTPStatusError except block around the async request
(the block handling resp = await self._post(...) and httpx.HTTPStatusError as
exc) only handles 401/403 and 404 but swallows all other status codes, causing
silent retries or treating failures as success; update that except block to
re-raise the original exc for any status codes not explicitly handled (i.e.,
after handling 401/403 -> raise AuthenticationError and 404 -> raise
URLNotFoundError, add a final raise exc), and mirror the same change in the sync
equivalent (the similar except block around the non-async _post call) so
unexpected HTTP errors are not silently replayed or passed to decode_json().

---

Nitpick comments:
In `@changelog/`+infp380.removed.md:
- Line 1: Update the changelog entry to explicitly note that callers who pass
the removed raise_for_error argument will now receive a TypeError; edit the
sentence mentioning the removed argument for execute_graphql, query_gql_query,
get_diff_summary, allocate_next_ip_address, and allocate_next_ip_prefix to add a
short parenthetical or following sentence like “Passing raise_for_error will now
raise TypeError” so the migration break is clear to readers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b0a82ae3-4f8c-4f22-9cc1-f9d43c0f54a1

📥 Commits

Reviewing files that changed from the base of the PR and between d566793 and b7b9b46.

📒 Files selected for processing (5)
  • changelog/+infp380.removed.md
  • docs/docs/python-sdk/sdk_ref/infrahub_sdk/client.mdx
  • infrahub_sdk/client.py
  • infrahub_sdk/ctl/utils.py
  • infrahub_sdk/ctl/validate.py
💤 Files with no reviewable changes (2)
  • infrahub_sdk/ctl/validate.py
  • infrahub_sdk/ctl/utils.py

Copy link
Copy Markdown
Contributor

@ogenstad ogenstad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, perhaps you can just create a test PR with your branch against the develop branch of Infrahub so that we can see if this argument is defined anywhere without our code.

@gmazoyer
Copy link
Copy Markdown
Contributor Author

gmazoyer commented Mar 17, 2026

LGTM, perhaps you can just create a test PR with your branch against the develop branch of Infrahub so that we can see if this argument is defined anywhere without our code.

It is used in some Infrahub backend tests that I will change in a dedicated PR, by using the commit produced by the merge of this PR for the SDK submodule.

@gmazoyer gmazoyer merged commit f7266eb into infrahub-develop Mar 17, 2026
21 checks passed
@gmazoyer gmazoyer deleted the gma-20260317-infp380 branch March 17, 2026 14:25
minitriga pushed a commit that referenced this pull request Mar 20, 2026
This parameter has been deprecated for a while and should not be used
anymore.
minitriga pushed a commit that referenced this pull request Mar 23, 2026
This parameter has been deprecated for a while and should not be used
anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants