Skip to content

Copy @direction when cloning the active context; guard the @direction null reset - #338

Open
skydudie wants to merge 3 commits into
digitalbazaar:masterfrom
skydudie:fix-direction-inheritance
Open

skydudie wants to merge 3 commits into
digitalbazaar:masterfrom
skydudie:fix-direction-inheritance

Conversation

@skydudie

@skydudie skydudie commented Sep 13, 2026

Copy link
Copy Markdown

Fixes #337.

What

Two fixes in _process_context-related direction handling, mirroring jsonld.js semantics per JSON-LD 1.1 API Context Processing:

  1. _clone_active_context now copies @direction, matching the existing handling of @language/@base/@vocab. Previously any context layer processed on top of an existing active context — a second document-level layer, a property-/type-scoped context, an embedded node @context, or a remote context — silently dropped the inherited default base direction (while the default language survived), changing expanded output and, under rdfDirection, the emitted N-Quads. (Default @direction is not inherited across context layers — _clone_active_context omits @direction #337; same bug as Default @direction is not inherited across context layers — _cloneActiveContext omits @direction jsonld.js#586; matching PR Copy @direction when cloning the active context jsonld.js#587.)
  2. A @direction: null context entry is now a no-op when no default direction is set (rval.pop('@direction', None) instead of an unguarded del). This mirrors JS delete semantics. Found while writing the tests: on released 3.3.0, jsonld.expand({'@context': {'@direction': None}, 'http://ex/p': 'v'}) raises KeyError: '@direction', and a legitimate scoped @direction: null reset is rejected as invalid scoped context.

Tests

  • Three TestExpand methods (per AGENTS.md, added to the existing class): default @direction survival across document-level layers, inheritance into a property-scoped context, and scoped override / null reset.
  • Full local run (pytest, W3C suites included via the specifications/ submodules): 1885 passed / 18 failed / 29 skipped / 1 xfailed on this branch vs 1882 / 18 / 29 / 1 on unpatched master — the failure lists are byte-identical (tests/test_cli.py JSON-decode issues and a missing aiohttp module in this environment), i.e. +3 new passing tests, zero regressions.
  • make lint clean.

Compatibility note

This changes expanded output (and N-Quads under rdfDirection) for documents that combine a default @direction with multiple context layers or scoped contexts — flagging for the 4.0.0 changelog since RDFC hashes over such documents change. Related: w3c/vc-data-integrity#366.

@mielvds mielvds left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @skydudie. Could you rebase against codex/255-split-iri-and-util-tests?

Comment thread CHANGELOG.md Outdated
@skydudie
skydudie changed the base branch from master to codex/255-split-iri-and-util-tests September 15, 2026 21:59
@skydudie
skydudie force-pushed the fix-direction-inheritance branch from 5b65a42 to d13ba5b Compare September 15, 2026 21:59
@skydudie

Copy link
Copy Markdown
Author

Thanks @skydudie. Could you rebase against codex/255-split-iri-and-util-tests?

Rebased onto codex/255-split-iri-and-util-tests and retargeted the PR to it. Moved the tests from tests/test_jsonld.py into tests/jsonld/test_expand.py

Lmk if there is anything else ya want changed😃

@mielvds
mielvds changed the base branch from codex/255-split-iri-and-util-tests to master September 16, 2026 07:41
@mielvds

mielvds commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

yes, could you rebase to master? :) I had a small fix in

@skydudie
skydudie force-pushed the fix-direction-inheritance branch from d13ba5b to a849bce Compare September 17, 2026 03:33
@skydudie

Copy link
Copy Markdown
Author

yes, could you rebase to master? :) I had a small fix in

Rebased onto master and thanks for the schema.org fix!

@mielvds

mielvds commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Thx @skydudie looks good. @anatoly-scherbakov could you have a final look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default @direction is not inherited across context layers — _clone_active_context omits @direction

2 participants