fix: allow a task related node to have no kind - #1219
Draft
pa-lem wants to merge 1 commit into
Draft
Conversation
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>
Deploying infrahub-sdk-python with
|
| 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 |
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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reading tasks with
include_related_nodes=Trueraises a PydanticValidationErrorwhen a taskreferences 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.kindwas typed as a requiredstr, soTask.from_graphqlfailed while constructing the model:The path is
manager.pyselecting{"id": None, "kind": None}forrelated_nodes, thenTask.from_graphqldoingTaskRelatedNode(**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.kindnon-null, so this case surfaced as a GraphQLerror 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.kindis nowstr | None = None.Tests
Added
test_from_graphql_related_node_without_kind, which parses a task carrying one resolvableand one unresolvable related node. Verified to fail before the change with the exact
ValidationErrorabove.tests/unit/sdk/test_task.pypasses 16/16.ruff check,ruff format --checkandmypyareclean on the touched files.
The full unit suite reports 3 failures —
test_repository_app.py::test_repo_list,test_repository_app.py::test_repo_initandtest_task_app.py::test_task_list_command— whichreproduce identically on unmodified
stable, so they are pre-existing and unrelated.Backporting
Targeting
stable. To be backported todevelopandinfrahub-develop, both of which still carrythe required
kind: str.🤖 Generated with Claude Code
Summary by cubic
Make
TaskRelatedNode.kindoptional to prevent crashes when reading tasks withinclude_related_nodes=Truethat reference deleted nodes. The SDK now acceptskind: nullfrom the server without a validation error.TaskRelatedNode.kindtostr | None = Noneininfrahub_sdk/task/models.py.test_from_graphql_related_node_without_kindto cover nullkindvalues.Written for commit 1cb2a6d. Summary will update on new commits.