Skip to content

fix(schema): keep the cached derived-value filter for own-id recomputes#9956

Merged
saltas888 merged 1 commit into
developfrom
fix-display-hfid-filter-key-mutation
Jul 20, 2026
Merged

fix(schema): keep the cached derived-value filter for own-id recomputes#9956
saltas888 merged 1 commit into
developfrom
fix-display-hfid-filter-key-mutation

Conversation

@gmazoyer

@gmazoyer gmazoyer commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Why

A node's display label and human-friendly id can include a value taken from a related node (read across a relationship). When Infrahub had to rebuild that value for the node itself, it sometimes did not update and kept showing the old value.

How it was found

This turned up while working on #9845 (refresh a reader when its read peer is deleted). After deleting a peer and merging, the reader's computed attribute refreshed, but its display label kept naming the deleted peer. The real cause was a separate, older bug in how display labels and HFIDs are rebuilt, so it gets its own fix here.

The bug

Each kind keeps one cached template for its display label and one for its HFID. Two paths share that cached template: one rebuilds the node by its own id, the other rebuilds it because a related node changed. The related-node path changed a lookup setting on the shared template and never reset it. So once a related-node rebuild had run, the own-id path used the wrong lookup, matched no node, and left the stored value stale.

The fix

The related-node path now works on a copy instead of editing the shared cached template, so the own-id path keeps its correct lookup.

Why this is separate from #9845 and does not replace it

They fix different bugs in different places:

So this PR does not supersede #9845. #9845 stays the main fix; this one clears the remaining display label gap. The delete-peer display label refresh only works once both are in.

Tests

The cross-node getter for display labels and human-friendly ids took the
cached template for the target kind and overwrote its filter_key in place
before returning it. The self getter hands back that same cached instance,
so one cross-node recompute flipped the cached filter from `ids` to the
relationship filter for good. A later own-id recompute then queried with the
relationship filter, matched no node, and left the stored value stale.

Return a copy with the overridden filter instead of mutating the cache.
@gmazoyer
gmazoyer requested a review from a team as a code owner July 17, 2026 12:44
@github-actions github-actions Bot added the group/backend Issue related to the backend (API Server, Git Agent) label Jul 17, 2026

@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 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Focused bug fix preventing shared cached instances from being mutated by cross-node getters. Bounded change with targeted tests confirming the cached filter is preserved for own-id recomputes.

Re-trigger cubic

@codspeed-hq

codspeed-hq Bot commented Jul 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing fix-display-hfid-filter-key-mutation (0f09275) with develop (e31f320)

Open in CodSpeed

import hashlib
from copy import deepcopy
from dataclasses import dataclass, field
from dataclasses import dataclass, field, replace

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TIL about replace()

@ajtmccarty ajtmccarty 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.

looks like a tough one to find. maybe worth sending to stable first?

@saltas888
saltas888 merged commit 73453bc into develop Jul 20, 2026
56 checks passed
@saltas888
saltas888 deleted the fix-display-hfid-filter-key-mutation branch July 20, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants