Skip to content

Commit 7902ebc

Browse files
authored
fix: Do extension resolution on loaded extensions from the model format (#2389)
We should call `ExtensionRegistry::load_json` instead of raw `serde_json::from_reader`, otherwise it skips the extension resolution steps. This failed in #2317, when changing the default binary encoding to `ModelWithExtensions`
1 parent 5da112b commit 7902ebc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

hugr-core/src/envelope.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ pub enum EnvelopeError {
293293
#[from]
294294
source: hugr_model::v0::ast::ResolveError,
295295
},
296+
/// Error reading a list of extensions from the envelope.
297+
#[error(transparent)]
298+
ExtensionLoad {
299+
/// The source error.
300+
#[from]
301+
source: crate::extension::ExtensionRegistryLoadError,
302+
},
296303
}
297304

298305
/// Internal implementation of [`read_envelope`] to call with/without the zstd decompression wrapper.
@@ -339,11 +346,8 @@ fn decode_model(
339346

340347
let mut extension_registry = extension_registry.clone();
341348
if format == EnvelopeFormat::ModelWithExtensions {
342-
let extra_extensions: Vec<Extension> =
343-
serde_json::from_reader::<_, Vec<Extension>>(stream)?;
344-
for ext in extra_extensions {
345-
extension_registry.register_updated(ext);
346-
}
349+
let extra_extensions = ExtensionRegistry::load_json(stream, &extension_registry)?;
350+
extension_registry.extend(extra_extensions);
347351
}
348352

349353
Ok(import_package(&model_package, &extension_registry)?)

0 commit comments

Comments
 (0)