Skip to content

Preserve query membership while a tag or component relation remains - #61

Merged
HexDecimal merged 1 commit into
HexDecimal:mainfrom
antonsoo:fix/preserve-overlapping-relation-queries
Oct 15, 2026
Merged

HexDecimal merged 1 commit into
HexDecimal:mainfrom
antonsoo:fix/preserve-overlapping-relation-queries

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

Removing a tag relation deletes the shared query indexes even when a component relation with the same origin, key and target still exists. Removing the component while keeping the tag has the same problem. Saving and loading rebuilds those indexes, so it unexpectedly changes query results.

import pickle
from tcod.ecs import Registry

world = Registry()
actor, faction = world["actor"], world["faction"]
actor.relation_tags_many[int].add(faction)
actor.relation_components[int][faction] = 42
query = world.Q.all_of(relations=[(int, faction)])
before = actor in query
actor.relation_tags_many[int].remove(faction)
after = actor in query
restored = pickle.loads(pickle.dumps(world))
after_load = restored["actor"] in restored.Q.all_of(
    relations=[(int, restored["faction"])])
print(before, after, after_load)
print(actor.relation_components[int][faction])

Before: True False True, with component value 42 still present. After: True True True, with the same component value.

Retain the index entry while either backing relation still owns it. Once the final relation is removed, normal index cleanup and cache invalidation continue. The guard checks membership, so a zero-valued component also keeps its relationship.

Regression coverage checks both removal orders, named and type keys, all four relation query forms and final cleanup. Faction-transition workflows with inherited actors and save/load checkpoints match separate dictionary state after the fix. The full suite, strict mypy and project hooks pass; the existing two XPASS cases and pytest parameter-iterator warning remain unchanged. No query syntax, save format or performance claim changes.

@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 (e5f0292) to head (08d20ca).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #61   +/-   ##
=======================================
  Coverage   99.16%   99.17%           
=======================================
  Files           9        9           
  Lines         959      965    +6     
=======================================
+ Hits          951      957    +6     
  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 merged commit 07ba4b8 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