Skip to content

Commit

Permalink
Fix for expected exception in put() methods (DM-25411)
Browse files Browse the repository at this point in the history
Added explicit check for empty attribute name and value in put() method,
this should work identically across all backends. Tested with postgres
on my CentOS7 virtual machine and it works OK now. Oracle is still not
tested but should work as well.
  • Loading branch information
andy-slac committed Jun 12, 2020
1 parent 5d56141 commit 6bdb880
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/lsst/daf/butler/registry/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def get(self, name: str, default: Optional[str] = None) -> Optional[str]:

def set(self, name: str, value: str, *, force: bool = False) -> None:
# Docstring inherited from ButlerAttributeManager.
if not name or not value:
raise ValueError("name and value cannot be empty")
if force:
self._db.replace(self._table, {
"name": name,
Expand Down
2 changes: 2 additions & 0 deletions python/lsst/daf/butler/registry/interfaces/_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def set(self, name: str, value: str, *, force: bool = False) -> None:
------
ButlerAttributeExistsError
Raised if attribute already exists but ``force`` option is false.
ValueError
Raised if name or value parameters are empty.
"""
raise NotImplementedError()

Expand Down
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,9 @@ def testAttributeManager(self):
self.assertEqual(len(list(attributes.items())), 0)

# cannot store empty key or value
with self.assertRaises(Exception):
with self.assertRaises(ValueError):
attributes.set("", "value")
with self.assertRaises(Exception):
with self.assertRaises(ValueError):
attributes.set("attr", "")

# set value of non-existing key
Expand Down

0 comments on commit 6bdb880

Please sign in to comment.