python-jsonschema / check-jsonschema

A CLI and set of pre-commit hooks for jsonschema validation with built-in support for GitHub Workflows, Renovate, Azure Pipelines, and more!
https://check-jsonschema.readthedocs.io/en/stable
Other
191 stars 39 forks source link

Fix cache handling bug with validation callback #454

Closed sirosen closed 3 days ago

sirosen commented 3 days ago

The validation_callback invocation in CacheDownloader forced redownloads even on a cache hit, in order to pass the response content to a parser.

After experimenting with several solutions, the easiest is to abstract out validation_callback into an arbitrary response_ok call which gets passed into the request fetching loop. response_ok is then a wrapper over the validation callback which can intentionally answer "yes" eagerly if a response evaluates to a cache hit -- a response which is a '200 Ok' and contains a Last-Modified header which scans as a hit should be treated as 'ok' regardless of its content.

In addition to the code changes, a regression test is included, which is demonstrated to fail on the current release.

resolves #453