Repository navigation
Make from_jsonld() respect ignore_unexpected_keys - #179
Merged
apdavison merged 1 commit intoOct 20, 2026
Merged
Conversation
As in openMINDS Python, raise NameError by default if a JSON-LD document contains keys that are not properties of the class, including in the linked nodes it contains, so that mistakes in documents written by hand are caught. Documents from the Knowledge Graph contain other keys, such as the space, so fairgraph always reads them with ignore_unexpected_keys=True, which now applies to the whole document.
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.
Currently,
KGObject.from_jsonld()accepts anignore_unexpected_keysargument but ignores it: keys that are not properties of the class are always silently dropped. The parameter can't simply be removed, since openMINDS Python'sload(), which fairgraph classes inherit, passes it on.With this PR,
from_jsonld()behaves as in openMINDS Python: by default, aNameErroris raised if the document contains keys that are neither properties of the class nor@context,@idor@type. This catches mistakes in JSON-LD documents written by hand, e.g. a misspelt property name, which are currently lost without any warning. It also applies toload()andCollection.load().Documents from the Knowledge Graph always contain other keys (the space, revision, identifiers, …), so everywhere fairgraph reads KG documents, it passes
ignore_unexpected_keys=True. Code that callsfrom_jsonld()on KG documents directly will need to do the same: this is noted in the release notes as a change in behaviour.The choice applies to the whole document, including linked nodes included in it (e.g. with
follow_links). Those are deserialized by openMINDS Python, which callsfrom_jsonld()without the argument, so the choice is passed to them through a context variable that is set for the duration of the outer call.