Skip to content

fix: keep the stored jsonschema when store_entity regenerates it - #216

Open
LukasGold wants to merge 1 commit into
mainfrom
fix/store-entity-keeps-jsonschema
Open

LukasGold wants to merge 1 commit into
mainfrom
fix/store-entity-keeps-jsonschema

Conversation

@LukasGold

@LukasGold LukasGold commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #215

Changes

  • store_entity passes the stored jsonschema slot as target_schema=. The old keyword schema= is not a field of AggregateGeneratedSchemasParam, so the aggregation always started from {} and dropped the hand-written schema.
  • A page without a jsonschema slot starts from {}, as before.
  • New function remove_generated_schema_section() in src/osw/core.py. It removes $defs/generated and the allOf entry {"$ref": "#/$defs/generated"}, as osl.util.postProcessPage in PageBot.js does.
  • store_entity calls it in DEFINITIONS_SECTION mode (Characteristics) before the aggregation, so the generated section is replaced instead of merged. It is called only when template generation produced at least one generated schema, so a failed generation keeps the stored schema.

Tests

New tests/test_store_entity_keeps_jsonschema.py, 5 tests. They run store_entity with offline=True and a fake site that serves the meta category, so no wiki is needed.

  • ROOT_LEVEL keeps hand-written properties.
  • DEFINITIONS_SECTION keeps $defs entries outside the generated section.
  • A second save with a different template drops a stale required and type, and $comment names the meta category once.
  • A template that produces invalid JSON leaves the stored schema unchanged.
  • A repeated ROOT_LEVEL save gives the same schema.

The first four tests failed on main before the fix. With only the target_schema= change, the stale-section test still failed at required.

Local gate: make check passed, make test reported 805 passed.

Not in this PR

As noted in the issue, resetGeneratedJsonLdContext and stripRootMembersSupersededByGenerated from PageBot.js are not ported.

Behaviour change in ROOT_LEVEL mode

ROOT_LEVEL mode applies to all Category pages except Characteristics.

  • Before this PR, every save started from {}. That dropped hand-written content, but it also removed generated entries that a later template no longer produces.
  • With this PR, the stored schema is kept. A root entry that a later template no longer produces now stays in the schema. This also applies to a page whose schema is fully generated.
  • merge_deep concatenates arrays. A template that changes "required": ["a"] to "required": ["b"] gives "required": ["a", "b"].

The generated keys in the root are not marked, so the code cannot tell a stale generated entry from a hand-written one. Removing only stale generated entries needs a record of the keys that the last generation wrote. That needs a maintainer decision.

- pass target_schema= instead of the ignored schema= (#215)
- replace $defs/generated in DEFINITIONS_SECTION mode instead of merging
- add offline regression tests through store_entity
@LukasGold
LukasGold requested a review from simontaurus October 16, 2026 16:32
@github-actions

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.8.3 (current: v2.8.2).

Changelog preview (truncated)
## v2.8.3 (2026-10-16)

### Bug Fixes

- Keep the stored jsonschema when store_entity regenerates it
  ([`9b76a8f`](https://github.com/OpenSemanticLab/osw-python/commit/9b76a8fbeb813b34c4881b54d329e9e837b08f95))

Preview via python-semantic-release and conventional commits.

@LukasGold
LukasGold requested a review from SimonStier October 22, 2026 16:44

This branch has not been deployed

No deployments
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.

store_entity discards the stored jsonschema slot and keeps a stale generated section

1 participant