Skip to content

fix(core): restore the page cache state once per fetch_schema call - #180

Merged
LukasGold merged 2 commits into
stagefrom
fix/176-fetch-schema-cache
Nov 12, 2026
Merged

LukasGold merged 2 commits into
stagefrom
fix/176-fetch-schema-cache

Conversation

@LukasGold

@LukasGold LukasGold commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #176.

Changes

  • OSW.fetch_schema reads the cache state once, enables the cache, and
    restores the state in a finally block around the loop over schema titles.
  • OSW._fetch_schema no longer reads or restores the cache state. A note in
    its docstring says where that now happens.
  • The model reload under if fetchSchemaParam.final: keeps the
    reload_module_or_restore(...) call from stage. Only the cache restore
    that followed it is removed.
  • New unit tests in tests/test_fetch_schema_cache.py.

Rationale

  • site_cache_state was a local of _fetch_schema, which runs once per title
    and again recursively per $ref. From the second title on, the snapshot
    already read the state the previous call had set, so if not site_cache_state was false and disable_cache() was never called.
  • The restore was also unreachable on two paths: the early return for a
    missing schema page, and any exception. A finally in the caller covers
    both, including an exception raised by reload_module_or_restore.
  • _fetch_schema is private and only called from fetch_schema and from
    itself, so moving the cache handling to the public method keeps the caching
    benefit for the whole operation.
  • enable_cache/disable_cache are plain boolean setters with no nesting
    counter, so a single enable and a single restore around the operation is the
    correct shape.

Verification

  • The 6 new tests pass.
  • The tests replace _fetch_schema with a stub, so they assert the cache
    contract of fetch_schema. They do not execute the body of _fetch_schema,
    which needs a wiki.
  • After merging stage, make check passes and make test reports 872
    passed.

Related

- fetch_schema takes the cache state before the loop over schema titles
- the restore runs in a finally block, so an early return or an exception
  in _fetch_schema can no longer leave the cache enabled
- _fetch_schema no longer snapshots a state its predecessor has changed
- add unit tests for the multi-title, exception and early-return paths

Closes #176
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.9.2 (current: v2.9.1).

Changelog preview (truncated)
## v2.9.2 (2026-11-12)

### Bug Fixes

- Follow properties and items when collecting category templates
  ([#220](https://github.com/OpenSemanticLab/osw-python/pull/220),
  [`55e500e`](https://github.com/OpenSemanticLab/osw-python/commit/55e500efb896f0a3d6bde98409b3a6f43a652bdc))

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

- Select category templates from the schema allOf like the wiki
  ([#220](https://github.com/OpenSemanticLab/osw-python/pull/220),
  [`9f606f4`](https://github.com/OpenSemanticLab/osw-python/commit/9f606f48fefd640cca48e6718f1a92eca118da6b))

### Continuous Integration

- Run Main on pushes to stage and Integration on PRs into stage
  ([`1b55f02`](https://github.com/OpenSemanticLab/osw-python/commit/1b55f02c90cae646d690f83d6208c01f0e26e62b))

### Documentation

- State which schema references the template walk follows
  ([#220](https://github.com/OpenSemanticLab/osw-python/pull/220),
  [`799bc07`](https://github.com/OpenSemanticLab/osw-python/commit/799bc07952aac7e6ab579bc127c5cb3000710491))

### Testing

- Drop the FileController type check, it is no longer a model
  ([`1eddbe8`](https://github.com/OpenSemanticLab/osw-python/commit/1eddbe867559e14806ad72eb076172cd41c7767e))

- Set subclass_of for oold 2 in the jsonschema tests
  ([`bd4ffdb`](https://github.com/OpenSemanticLab/osw-python/commit/bd4ffdb3e950f43f4eea0151d19d07f621eb14e0))

Preview via python-semantic-release and conventional commits.

@LukasGold
LukasGold merged commit 477f4ca into stage Nov 12, 2026
12 checks passed
@LukasGold
LukasGold deleted the fix/176-fetch-schema-cache branch November 12, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetch_schema leaves the page cache enabled when given more than one schema title

1 participant