Repository navigation
Resolve reverse links using the forward property's path, not its Python name - #160
Merged
apdavison merged 1 commit intoOct 18, 2026
Conversation
…on name (#92) Resolving or counting a reverse property sent the same filter, keyed by a single Python name, to every target class. The forward property that makes the link does not always have the same name in each class (e.g. "license" in DatasetVersion, "licenses" in ModelVersion), so query generation raised "Invalid filter" and nothing was returned. Where a reverse property stands for several forward properties, only the first was queried. KGQuery.from_reverse_property() now builds one filter for each forward property whose path matches, in each target class, and resolve() returns each node once even if it links through more than one of them. Also remove the reverse-KGQuery block in `KGObject.__init__`, which never ran: `KGNode.__init__` has already set every reverse property, and it passed a `callback` argument that `KGQuery` does not accept.
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.
Fixes #92.
Currently, resolving or counting a reverse property (e.g.
license.is_applied_to.resolve(client)) sends the same filter, keyed by a single Python name, to every target class. The forward property that makes the link does not always have the same Python name in each class: it islicenseinDatasetVersionbutlicensesinModelVersionandSoftwareVersion. For such classes query generation raisesValueError: Invalid filter, so the whole reverse property cannot be resolved. Onmasterthis affects 17 (reverse property, target class) pairs in v4 and 14 in v5.In addition, 72 reverse properties stand for several forward properties (e.g.
BehavioralProtocol.used_incoversassociated_protocols,behavioral_protocolsandprotocols), but only the first is queried, which fails for any target class that lacks it.This PR adds
KGQuery.from_reverse_property(), which identifies the forward properties by their path (the same in every class) rather than by Python name. It builds one filter for each matching forward property in each target class.resolve()andcount()use these per-class filters, andresolve()returns each node once even when it links through more than one property (asProtocolExecutioncan, via bothbehavioral_protocolsandprotocols, in v5).count()counts such a node once per property, as documented in its docstring.It also removes the reverse-
KGQueryblock inKGObject.__init__, which never runs:KGNode.__init__has already set every reverse property, and it passes acallbackargument thatKGQuerydoes not accept.Tests:
license/licensescase, the v5 two-property case, and de-duplication inresolve()CC-BY-4.0'sis_applied_to.count()succeedsNot covered here: reverse links whose targets are embedded classes (#82), and
MRIScannerUsage, whose query generation fails for a separate reason.