Skip to content

Add ability to clear loaded schema cache. #1968

@WilliamJamieson

Description

@WilliamJamieson

The schemas opened via asdf.schema.load_schema are cached using:

asdf/asdf/schema.py

Lines 462 to 488 in a346a6b

@lru_cache
def _load_schema_cached(url, resolver, resolve_references):
loader = _make_schema_loader(resolver)
schema, url = loader(url)
if resolve_references:
def resolve_refs(node, json_id):
if json_id is None:
json_id = url
if isinstance(node, dict) and "$ref" in node:
suburl_base, suburl_fragment = _safe_resolve(resolver, json_id, node["$ref"])
if suburl_base == url or suburl_base == schema.get("id"):
# This is a local ref, which we'll resolve in both cases.
subschema = schema
else:
subschema = load_schema(suburl_base, resolver, True)
return reference.resolve_fragment(subschema, suburl_fragment)
return node
schema = treeutil.walk_and_modify(schema, resolve_refs)
return schema

This can present a problem when working with schema resources that are not included in asdf under normal operations. During testing I want to be able to load those schemas, but later I want loading those schemas to fail. This is because otherwise I end up with a situation where the order that tests are run influences whether or not tests pass or fail.

Thus it would be useful to have a mechanism to clear this cache without having to access it through a private API with asdf.schema._load_schema_cached.cache_clear().

Alternately, we may want to make the schema cache tied to the current AsdfConfig so things like what I am trying to do can be done within a special AsdfConfig context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions