From 0b8186d14732e4cd7702d9e62bd598f9a365186c Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Fri, 17 Jul 2026 15:21:38 -0400 Subject: [PATCH] Allow regular mutable mappings for metadata failure annnotations. This is motivated by lsst.images types, which have a regular dict for their metadata instead of a PropertySet-like. --- python/lsst/pipe/base/_status.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/python/lsst/pipe/base/_status.py b/python/lsst/pipe/base/_status.py index 617398ef1..a058f437d 100644 --- a/python/lsst/pipe/base/_status.py +++ b/python/lsst/pipe/base/_status.py @@ -44,6 +44,7 @@ import enum import logging import sys +from collections.abc import MutableMapping from typing import TYPE_CHECKING, Any, ClassVar, Protocol import pydantic @@ -359,7 +360,7 @@ class GetSetDictMetadataHolder(Protocol): """ @property - def metadata(self) -> GetSetDictMetadata | None: + def metadata(self) -> GetSetDictMetadata | MutableMapping[str, Any] | None: pass @@ -500,7 +501,8 @@ def annotate( Exception that caused the task to fail. *args : `GetSetDictMetadataHolder` Objects (e.g. Task, Exposure, SimpleCatalog) to annotate with - failure information. They must have a `metadata` property. + failure information. They must have a `metadata` property that + is a `~collections.abc.MutableMapping`. log : `logging.Logger` Log to send error message to. @@ -548,7 +550,10 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs): # Some outputs may not exist, so we cannot set metadata on them. if item is None: continue - item.metadata.set_dict("failure", failure_info) # type: ignore + if hasattr(item.metadata, "set_dict"): + item.metadata.set_dict("failure", failure_info) # type: ignore + elif isinstance(item.metadata, MutableMapping): + item.metadata["failure"] = failure_info log.debug( "Task failed with only partial outputs; see exception message for details.",