-
Notifications
You must be signed in to change notification settings - Fork 56
fix(schema): keep the cached derived-value filter for own-id recomputes #9956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+54
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
43 changes: 43 additions & 0 deletions
43
backend/tests/unit/core/schema/test_schema_branch_derived_filter_key.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Resolving a cross-node derived value must not corrupt the cached own-id filter. | ||
|
|
||
| Display labels and HFIDs cache one template per kind. The self getter and the related (cross-node) | ||
| getter share that cached instance, so the related getter must return a copy rather than overwrite the | ||
| cached ``filter_key`` - otherwise a later own-id recompute queries with the relationship filter and | ||
| silently matches nothing. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from copy import deepcopy | ||
|
|
||
| from infrahub.core.schema.schema_branch import SchemaBranch | ||
| from tests.helpers.merge_recompute.dataset import PROFILE_NODE_KIND, PROFILE_PEER_KIND, build_profile_schema | ||
|
|
||
|
|
||
| def _profile_schema_branch(*, hfid_reads_peer: bool = False) -> SchemaBranch: | ||
| schema = deepcopy(build_profile_schema()) | ||
| if hfid_reads_peer: | ||
| node = next(node for node in schema.nodes if node.kind == PROFILE_NODE_KIND) | ||
| node.human_friendly_id = ["name__value", "peer__name__value"] | ||
| schema_branch = SchemaBranch(cache={}, name="test") | ||
| schema_branch.load_schema(schema=schema) | ||
| schema_branch.process() | ||
| return schema_branch | ||
|
|
||
|
|
||
| def test_get_related_template_does_not_mutate_cached_filter_key() -> None: | ||
| display_labels = _profile_schema_branch().display_labels | ||
|
|
||
| related = display_labels.get_related_template(related_kind=PROFILE_PEER_KIND, target_kind=PROFILE_NODE_KIND) | ||
|
|
||
| assert related.filter_key == "peer__ids" | ||
| assert display_labels.get_template_node(kind=PROFILE_NODE_KIND).filter_key == "ids" | ||
|
|
||
|
|
||
| def test_get_related_definition_does_not_mutate_cached_filter_key() -> None: | ||
| hfids = _profile_schema_branch(hfid_reads_peer=True).hfids | ||
|
|
||
| related = hfids.get_related_definition(related_kind=PROFILE_PEER_KIND, target_kind=PROFILE_NODE_KIND) | ||
|
|
||
| assert related.filter_key == "peer__ids" | ||
| assert hfids.get_node_definition(kind=PROFILE_NODE_KIND).filter_key == "ids" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed display labels and human-friendly ids that read across a relationship not refreshing when they were recomputed by their own id. Resolving a cross-node template overwrote the cached own-id filter in place, so a later self recompute queried with the relationship filter, matched no node, and left the stored value stale. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about
replace()