Populate save_cache when save() creates an instance - #140
Merged
apdavison merged 1 commit intoSep 13, 2026
Merged
Conversation
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 withsave_cache, but the cache was only written whenexists()found an instance by query, not whensave()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_cachesfixture intest_save_new_recursive_mock, whose created instances now leave entries in the global save cache.Fixes #137