Skip to content

fix: allow a task related node to have no kind - #1219

Draft
pa-lem wants to merge 1 commit into
stablefrom
ple-task-related-node-nullable-kind-stable
Draft

fix: allow a task related node to have no kind#1219
pa-lem wants to merge 1 commit into
stablefrom
ple-task-related-node-nullable-kind-stable

Conversation

@pa-lem

@pa-lem pa-lem commented Jul 29, 2026

Copy link
Copy Markdown

Problem

Reading tasks with include_related_nodes=True raises a Pydantic ValidationError when a task
references a node that no longer exists in the graph.

A task outlives the nodes it references. When a related node's vertex is gone, the server cannot
resolve a kind for it and returns kind: null. TaskRelatedNode.kind was typed as a required
str, so Task.from_graphql failed while constructing the model:

pydantic_core._pydantic_core.ValidationError: 1 validation error for TaskRelatedNode
kind
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]

The path is manager.py selecting {"id": None, "kind": None} for related_nodes, then
Task.from_graphql doing TaskRelatedNode(**item) on each entry.

This turns a server-side condition the API now handles gracefully into a client-side crash.

Server side

Infrahub previously declared TaskRelatedNode.kind non-null, so this case surfaced as a GraphQL
error rather than a null value. That is being corrected in
opsmill/infrahub#10075, which makes the field nullable. This change is the SDK half: without it,
the same tasks fail with a validation error instead.

The two are intentionally not coupled by a submodule bump, so this can land and be released on its
own schedule.

Change

TaskRelatedNode.kind is now str | None = None.

Tests

Added test_from_graphql_related_node_without_kind, which parses a task carrying one resolvable
and one unresolvable related node. Verified to fail before the change with the exact
ValidationError above.

tests/unit/sdk/test_task.py passes 16/16. ruff check, ruff format --check and mypy are
clean on the touched files.

The full unit suite reports 3 failures — test_repository_app.py::test_repo_list,
test_repository_app.py::test_repo_init and test_task_app.py::test_task_list_command — which
reproduce identically on unmodified stable, so they are pre-existing and unrelated.

Backporting

Targeting stable. To be backported to develop and infrahub-develop, both of which still carry
the required kind: str.

🤖 Generated with Claude Code


Summary by cubic

Make TaskRelatedNode.kind optional to prevent crashes when reading tasks with include_related_nodes=True that reference deleted nodes. The SDK now accepts kind: null from the server without a validation error.

  • Bug Fixes
    • Set TaskRelatedNode.kind to str | None = None in infrahub_sdk/task/models.py.
    • Added test_from_graphql_related_node_without_kind to cover null kind values.

Written for commit 1cb2a6d. Summary will update on new commits.

Review in cubic

The server cannot resolve a kind for a related node whose vertex is no longer
in the graph, and now returns null for it rather than failing the query. The
model still required a string, so reading such a task with
include_related_nodes=True raised a validation error client-side.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1cb2a6d
Status: ✅  Deploy successful!
Preview URL: https://2e62f62e.infrahub-sdk-python.pages.dev
Branch Preview URL: https://ple-task-related-node-nullab.infrahub-sdk-python.pages.dev

View logs

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@           Coverage Diff           @@
##           stable    #1219   +/-   ##
=======================================
  Coverage   82.47%   82.47%           
=======================================
  Files         138      138           
  Lines       12186    12186           
  Branches     1833     1833           
=======================================
  Hits        10051    10051           
  Misses       1572     1572           
  Partials      563      563           
Flag Coverage Δ
integration-tests 40.56% <0.00%> (-0.01%) ⬇️
python-3.10 56.27% <0.00%> (+0.01%) ⬆️
python-3.11 56.26% <0.00%> (-0.02%) ⬇️
python-3.12 56.26% <0.00%> (ø)
python-3.13 56.27% <0.00%> (+0.01%) ⬆️
python-3.14 56.27% <0.00%> (ø)
python-filler-3.12 22.21% <100.00%> (ø)

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

Files with missing lines Coverage Δ
infrahub_sdk/task/models.py 98.27% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

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.

1 participant