Skip to content

Support list values in existence queries - #159

Merged
apdavison merged 1 commit into
HumanBrainProject:masterfrom
apdavison:existence-query-lists
Oct 17, 2026
Merged

apdavison merged 1 commit into
HumanBrainProject:masterfrom
apdavison:existence-query-lists

Conversation

@apdavison

Copy link
Copy Markdown
Member

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.

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.
@apdavison apdavison added the bug Something isn't working label Oct 17, 2026
@apdavison apdavison added this to the 0.16 milestone Oct 17, 2026
@apdavison
apdavison merged commit fb19ed2 into HumanBrainProject:master Oct 17, 2026
6 checks passed
@apdavison
apdavison deleted the existence-query-lists branch October 17, 2026 20:17
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.

1 participant