Skip to content

Commit

Permalink
Merge pull request #534 from lsst/tickets/DM-30685
Browse files Browse the repository at this point in the history
DM-30685: Issue warning if lookup key dimension is not known to universe
  • Loading branch information
timj committed Jun 11, 2021
2 parents 0e603c7 + 4e9a1e5 commit 58f5464
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/changes/DM-30685.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
If an unrecognized dimension is used as a look up key in a configuration file (using the ``+`` syntax) a warning is used suggesting a possible typo rather than a confusing `KeyError`.
This is no longer a fatal error and the key will be treated as a name.
21 changes: 18 additions & 3 deletions python/lsst/daf/butler/core/configSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,28 @@ def __init__(self, name: Optional[str] = None,
raise ValueError(f"Supplied name must be str not: '{name}'")

if "+" in name:
if universe is None:
raise ValueError(f"Cannot construct LookupKey for {name} without dimension universe.")

# If we are given a single dimension we use the "+" to
# indicate this but have to filter out the empty value
dimension_names = [n for n in name.split("+") if n]
if universe is None:
raise ValueError(f"Cannot construct LookupKey for {name} without dimension universe.")
else:
try:
self._dimensions = universe.extract(dimension_names)
except KeyError:
# One or more of the dimensions is not known to the
# universe. This could be a typo or it could be that
# a config is being used that is not compatible with
# this universe. Use the name directly as a lookup key
# but issue a warning. This will be potentially annoying
# in the scenario where a lookup key comes from a
# default config but the users are using an external
# universe.
unknown = [name for name in dimension_names if universe.get(name) is None]
log.warning("A LookupKey '%s' uses unknown dimensions: %s. Possible typo?"
" Using the name explicitly.",
name, unknown)
self._name = name
else:
self._name = name

Expand Down

0 comments on commit 58f5464

Please sign in to comment.