#8237 (IFC-2235): Update queries on node using HFID to reference relationships #8480
#8237 (IFC-2235): Update queries on node using HFID to reference relationships #8480polmichel merged 6 commits intorelease-1.8from
Conversation
WalkthroughThis PR fixes a bug where relationship-based display_label variables became None after upserts. It adds two Node helpers, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
…ld require additional information from related nodes
d11fb49 to
e591e10
Compare
e591e10 to
9288b49
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@backend/tests/component/graphql/test_mutation_upsert.py`:
- Around line 852-855: The helper _basic_asserts is declared async but contains
no awaits and lacks a return type; change its signature from "async def
_basic_asserts(...)" to a synchronous function "def
_basic_asserts(result_upsert: ExecutionResult) -> None:" so it is no longer a
coroutine and includes the explicit None return type while keeping the same
assertion body.
In `@dev/guidelines/backend/python.md`:
- Around line 58-71: The example showing the deferred import uses TYPE_CHECKING
but omits its import; add "from typing import TYPE_CHECKING" to the snippet so
the block with "if TYPE_CHECKING:" and the deferred "from
infrahub.core.schema.schema_branch import SchemaBranch" is runnable and the
function signature "def collect_filters(self, schema_branch: SchemaBranch) ->
dict[str, set[str]]:" remains valid.
In `@dev/knowledge/backend/display-labels-and-hfid.md`:
- Line 1: Update the markdown title string to use hyphenation: change "Human
Friendly IDs" to "Human-Friendly IDs" in the top-level heading (the header text
in the file's first line, "# Display Labels and Human-Friendly IDs") so the
title reads "# Display Labels and Human-Friendly IDs".
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
backend/infrahub/core/node/__init__.pybackend/tests/component/graphql/test_mutation_upsert.pychangelog/8237.fixed.mddev/guidelines/backend/python.mddev/knowledge/backend/display-labels-and-hfid.mddev/knowledge/backend/mutations.md
There was a problem hiding this comment.
🧹 Nitpick comments (1)
dev/guidelines/backend/python.md (1)
58-73: Consider addingfrom __future__ import annotationsto both snippets for completeness.While the TYPE_CHECKING import issue from the past review has been addressed (line 66 correctly shows the import), both the "bad" and "good" examples would benefit from including
from __future__ import annotationsat the start. Line 45 establishes this as a universal requirement ("All backend modules use..."), so showing it in both snippets would:
- Make each snippet runnable when copied in isolation
- Reinforce that the future import is the foundation enabling the TYPE_CHECKING pattern
- Clarify that even with string annotations, top-level imports still execute and can cause circular dependencies
📝 Proposed documentation enhancement
# ❌ Bad - top-level import only used in annotations; causes circular import +from __future__ import annotations + from infrahub.core.schema.schema_branch import SchemaBranch def collect_filters(self, schema_branch: SchemaBranch) -> dict[str, set[str]]: ... # ✅ Good - deferred under TYPE_CHECKING +from __future__ import annotations + from typing import TYPE_CHECKING if TYPE_CHECKING:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dev/guidelines/backend/python.md` around lines 58 - 73, Add "from __future__ import annotations" at the top of both the "bad" and "good" example snippets so annotations are deferred and the TYPE_CHECKING pattern works as intended; specifically, ensure the future import appears before any other imports or code in the examples that reference SchemaBranch and the collect_filters(self, schema_branch: SchemaBranch) signature, and keep the TYPE_CHECKING block and the deferred import of infrahub.core.schema.schema_branch unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@dev/guidelines/backend/python.md`:
- Around line 58-73: Add "from __future__ import annotations" at the top of both
the "bad" and "good" example snippets so annotations are deferred and the
TYPE_CHECKING pattern works as intended; specifically, ensure the future import
appears before any other imports or code in the examples that reference
SchemaBranch and the collect_filters(self, schema_branch: SchemaBranch)
signature, and keep the TYPE_CHECKING block and the deferred import of
infrahub.core.schema.schema_branch unchanged.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
backend/tests/component/graphql/test_mutation_upsert.pydev/guidelines/backend/python.mddev/knowledge/backend/display-labels-and-hfid.md
🚧 Files skipped from review as they are similar to previous changes (2)
- dev/knowledge/backend/display-labels-and-hfid.md
- backend/tests/component/graphql/test_mutation_upsert.py
…#8480) * IFC-2235 integration test replicating the issue * IFC-2235 HFID and Display Labels recomputation during node update could require additional information from related nodes * IFC-2235 refactor common behavior in the same method * IFC-2235 towncrier (#8237) * IFC-2235 /feedback command usage * IFC-2235 address code review feedbacks
Why
Problem statement
Update queries recompute and provide incorrect values for computed attributes using related node attributes.
For example, after an update query on an object with the following schema:
display_labelwill be evaluated as "name__value(None)", because{{ manufacturer__name__value }}evaluates toNone.This is due to the fact that
infrahub.core.node.Node.resolve_relationshipsmethod does not retrieve the required attributes from the relationships when the node is not being created.This
display_labelrecompute is called in theinfrahub.core.node.Node._updatemethod due to a legitimate call toinfrahub.core.node.node_property_attribute.NodePropertyAttribute.needs_update.Closes #8237 / IFC-2235
What changed
Condition that queries additional attributes from the database when resolving the
relationshipsininfrahub.core.node.Node.resolve_relationships.Before this PR, this was only triggered during node creation.
After this PR, this will be called:
How to test
Impact & rollout
Checklist
uv run towncrier create ...)Summary by CodeRabbit
Bug Fixes
Refactor
Documentation
Tests