Skip to content

Populate save_cache when save() creates an instance - #140

Merged
apdavison merged 1 commit into
HumanBrainProject:masterfrom
apdavison:fix-save-cache-on-create
Sep 13, 2026
Merged

apdavison merged 1 commit into
HumanBrainProject:masterfrom
apdavison:fix-save-cache-on-create

Conversation

@apdavison

Copy link
Copy Markdown
Member

The KG is only eventually consistent, so an instance that has just been created may not yet appear in existence queries. exists() guards against this with save_cache, but the cache was only written when exists() found an instance by query, not when save() created one (the write was lost with the KG v2 code in 8564c75). Saving a second, separately-constructed but equivalent object in the same session could therefore create a duplicate.

The create branch of save() now adds a cache entry, unless no existence query can be built for the object, in which case duplicates remain allowed as before.

Adds tests for both cases, and uses the clear_caches fixture in test_save_new_recursive_mock, whose created instances now leave entries in the global save cache.

Fixes #137

The KG is only eventually consistent, so an instance that has just been created may not yet appear in existence queries. exists() guards against this with save_cache, but the cache was only written when exists() found an instance by query, not when save() created one (the write was lost with the KG v2 code in 8564c75). Saving a second, separately-constructed but equivalent object in the same session could therefore create a duplicate.

The create branch of save() now adds a cache entry, unless no existence query can be built for the object, in which case duplicates remain allowed as before.

Adds tests for both cases, and uses the clear_caches fixture in test_save_new_recursive_mock, whose created instances now leave entries in the global save cache.
@apdavison apdavison added this to the 0.15 milestone Sep 13, 2026
@apdavison apdavison added the bug Something isn't working label Sep 13, 2026
@apdavison
apdavison merged commit fcebe5f into HumanBrainProject:master Sep 13, 2026
6 checks passed
@apdavison
apdavison deleted the fix-save-cache-on-create branch September 13, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

save() does not populate save_cache when creating an instance, leaving the eventual-consistency window unguarded

1 participant