Skip to content

Rebuild saved component relation indexes with their target entities - #57

Merged
HexDecimal merged 2 commits into
HexDecimal:mainfrom
antonsoo:fix/restore-component-relation-targets
Oct 13, 2026
Merged

HexDecimal merged 2 commits into
HexDecimal:mainfrom
antonsoo:fix/restore-component-relation-targets

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

Loading a registry preserves component relation values but rebuilds their specific-target query index with the origin in place of the target:

import pickle
from tcod.ecs import Registry

world = Registry()
world["moon"].relation_components[int][world["planet"]] = 10
print([e.uid for e in world.Q.all_of(relations=[(int, world["planet"])])])
world = pickle.loads(pickle.dumps(world))
print([e.uid for e in world.Q.all_of(relations=[(int, world["planet"])])])
print([e.uid for e in world.Q.all_of(relations=[(int, world["moon"])])])

The current output is ['moon'], [], ['moon']. It should be ['moon'], ['moon'], []: loading creates neither a missing planet relation nor a self-relation.

Use target in _relations_lookup_from, matching _relations_lookup_add. This changes a derived lookup table, without changing the stored relation data or save format.

Regressions cover ordinary/named component keys, pickle protocols 2/4/5, specific and wildcard forward/reverse queries, the spurious self-match and unchanged tag relations. In 54 native saved orbital-scene configurations, all 2,934 incorrect specific-target query results are corrected. Every query matches its pre-save result; component values, reverse/tag controls and serialized byte hashes remain unchanged. The full pytest/doctest suite, mypy and project-pinned Ruff checks pass. Existing xpasses and the pytest parametrization warning are also present on main.

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (deeca21) to head (2d6ccf6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #57   +/-   ##
=======================================
  Coverage   99.15%   99.15%           
=======================================
  Files           9        9           
  Lines         949      949           
=======================================
  Hits          941      941           
  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 self-assigned this Oct 13, 2026
@HexDecimal
HexDecimal merged commit 491d938 into HexDecimal:main Oct 13, 2026
1 check passed
@HexDecimal

HexDecimal commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

This was a critical fix. I've added this to the changelog myself.

I'll likely make a new release soon.

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