Repository navigation
Support list values in existence queries - #159
Merged
apdavison merged 1 commit intoOct 17, 2026
Merged
Conversation
Previously, `_build_existence_query()` raised `CannotBuildExistenceQuery("not implemented yet")` if any of a class's existence-query properties held a list, so `exists()` and `save()` treated such objects as new, creating duplicates on repeated saves, and the save cache was never filled for them. This affects any class with a multi-valued existence-query property, e.g. `Chapter.authors` or `LearningResource.about`.
A list value now becomes a list in the existence query, which is expressed in the KG query using the support for lists of filter values: every local item must be present in the KG, but the order of the items is ignored, as are any additional items in the KG. Linked nodes are given by ID, and embedded or unsaved nodes by a sub-query, kept as a separate dict for each item so that all its filters must match the same node in the KG. An empty list is treated as a missing value.
To support this, `expand_filter()` now expands dicts within lists, and `normalize_filter()` normalizes each item of such a list separately. A linked node whose class has no existence query now raises `CannotBuildExistenceQuery` rather than an `AttributeError`.
This also fixes `generate_cache_key()` for lists: it used the whole list in place of each item and omitted the property name, so different queries could share a key. Item order no longer affects the key.
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.
Previously,
_build_existence_query()raisedCannotBuildExistenceQuery("not implemented yet")if any of a class's existence-query properties held a list, soexists()andsave()treated such objects as new, creating duplicates on repeated saves, and the save cache was never filled for them. This affects any class with a multi-valued existence-query property, e.g.Chapter.authorsorLearningResource.about.A list value now becomes a list in the existence query, which is expressed in the KG query using the support for lists of filter values: every local item must be present in the KG, but the order of the items is ignored, as are any additional items in the KG. Linked nodes are given by ID, and embedded or unsaved nodes by a sub-query, kept as a separate dict for each item so that all its filters must match the same node in the KG. An empty list is treated as a missing value.
To support this,
expand_filter()now expands dicts within lists, andnormalize_filter()normalizes each item of such a list separately. A linked node whose class has no existence query now raisesCannotBuildExistenceQueryrather than anAttributeError.This also fixes
generate_cache_key()for lists: it used the whole list in place of each item and omitted the property name, so different queries could share a key. Item order no longer affects the key.