Skip to content

Snapshot inherited component relation inputs before replacement - #62

Merged
HexDecimal merged 2 commits into
HexDecimal:mainfrom
antonsoo:fix/snapshot-inherited-relation-input
Oct 15, 2026
Merged

HexDecimal merged 2 commits into
HexDecimal:mainfrom
antonsoo:fix/snapshot-inherited-relation-input

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

Replacing a prefab's component relations from an instance's inherited mapping silently loses values: clearing the destination also changes the live source before its items are read.

import tcod.ecs
world = tcod.ecs.Registry()
prefab, target = world['prefab'], world['target']
prefab.relation_components[int][target] = 3
instance = prefab.instantiate()
prefab.relation_components[int] = instance.relation_components[int]
print(dict(prefab.relation_components[int]))
# before: {}; after: {target: 3}

Snapshot the input pairs before clearing the destination, matching the existing approach for tag-relation assignment. Component objects are retained by reference; this adds an O(n) temporary tuple of pairs. The same-entity/same-key no-op guard stays unchanged. Add regressions for named/unnamed keys, one/three inheritance levels, overrides and warmed queries, plus a changelog entry.

Validation on current main 07ba4b8 (including #61):

  • Eight new cases fail before and pass afterward. Full suite on Python 3.10 and 3.12: 96 passed, two existing xpasses and one existing warning; baseline is 88 passed with the same xpasses/warning.
  • In 48 executed prefab-edit/save/load game scenarios, 784 lost relation entries, 23,520 missing actor-query memberships and 7,680 wrong target decisions become zero. All 48 frozen baseline archive hashes and all copied-dictionary control histories remain exact; both Python versions agree. This is a constructed game-system workload, not a claim about a released game.
  • Full mypy passes; applicable pre-commit checks, Ruff lint and formatting pass.

This is separate from #59's distinct-key no-op guard and #61's overlapping tag/component query indexes: the input here inherits data from the destination being replaced.

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (07ba4b8) to head (a591383).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #62   +/-   ##
=======================================
  Coverage   99.17%   99.17%           
=======================================
  Files           9        9           
  Lines         965      966    +1     
=======================================
+ Hits          957      958    +1     
  Misses          8        8           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HexDecimal HexDecimal left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Treating these as collections has been awkward with how Python references everything. At least the solution to these issues is often to simply make a copy of the mutable state before processing.

Thanks for more of these fixes and tests.

Comment thread CHANGELOG.md Outdated
### Fixed

- Replacing component relations from an inherited view now preserves values which depend on the destination.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Extra newline here.

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.

Removed the extra blank line. Thanks for reviewing.

@HexDecimal
HexDecimal merged commit 7e852c0 into HexDecimal:main Oct 15, 2026
14 checks passed
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.

2 participants