Skip to content

Commit 34eb4ae

Browse files
Fixes for the explicit pattern properties change
1 parent d458bba commit 34eb4ae

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/roman_datamodels/_maker_utils/_ref_files.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,7 @@ def _mk_phot_table(shape=(4096,), **kwargs):
629629
"""
630630
Create the phot_table for the photom reference file.
631631
"""
632-
return {
633-
entry: _mk_phot_table_entry(entry, shape, **kwargs.get(entry, {})) for entry in (*OPT_ELEM, "GRISM_0", "NOT_CONFIGURED")
634-
}
632+
return {entry: _mk_phot_table_entry(entry, shape, **kwargs.get(entry, {})) for entry in (*OPT_ELEM, "GRISM_0")}
635633

636634

637635
def mk_wfi_img_photom(*, shape=(4096,), filepath=None, **kwargs):

src/roman_datamodels/stnode/_schema.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import TYPE_CHECKING
1212

1313
import asdf
14-
import asdf.schema
14+
import asdf.treeutil
1515
from semantic_version import Version
1616

1717
from ._registry import NODE_CLASSES_BY_TAG, SCHEMA_URIS_BY_TAG
@@ -27,6 +27,42 @@
2727
NOBOOL = False
2828

2929

30+
@functools.cache
31+
def _load_schema(schema_uri: str) -> dict[str, Any]:
32+
"""
33+
Load a schema by URI.
34+
35+
Parameters
36+
----------
37+
uri : str
38+
The URI of the schema to load.
39+
"""
40+
# See Issue https://github.com/asdf-format/asdf/issues/1977
41+
if Version(asdf.__version__) < Version("5.1.0"):
42+
schema = asdf.schema.load_schema(schema_uri, resolve_references=False)
43+
44+
def resolve_refs(node, json_id):
45+
if json_id is None:
46+
json_id = schema_uri
47+
48+
if isinstance(node, dict) and "$ref" in node:
49+
suburl_base, suburl_fragment = asdf.schema._safe_resolve(json_id, node["$ref"])
50+
51+
if suburl_base == schema_uri or suburl_base == schema.get("id"):
52+
# This is a local ref, which we'll resolve in both cases.
53+
subschema = schema
54+
else:
55+
subschema = asdf.schema.load_schema(suburl_base, True)
56+
57+
return asdf.treeutil.walk_and_modify(asdf.reference.resolve_fragment(subschema, suburl_fragment), resolve_refs)
58+
59+
return node
60+
61+
return asdf.treeutil.walk_and_modify(schema, resolve_refs) # type: ignore[no-any-return]
62+
63+
return asdf.schema.load_schema(schema_uri, resolve_references=True) # type: ignore[no-any-return]
64+
65+
3066
@functools.cache
3167
def get_latest_schema(uri: str) -> tuple[str, dict[str, Any]]:
3268
"""
@@ -51,7 +87,7 @@ def get_latest_schema(uri: str) -> tuple[str, dict[str, Any]]:
5187
if latest_uri is None:
5288
raise ValueError(f"No schema found for {uri}")
5389

54-
return latest_uri, asdf.schema.load_schema(latest_uri, resolve_references=True)
90+
return latest_uri, _load_schema(latest_uri)
5591

5692

5793
@functools.cache
@@ -66,7 +102,7 @@ def _get_schema_from_tag(tag):
66102
"""
67103
schema_uri = SCHEMA_URIS_BY_TAG[tag]
68104

69-
return asdf.schema.load_schema(schema_uri, resolve_references=True)
105+
return _load_schema(schema_uri)
70106

71107

72108
class _MissingKeywordType:

0 commit comments

Comments
 (0)