Skip to content

Commit

Permalink
Catch and reraise the IntegrityError in collections.x_remove
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 19, 2024
1 parent 13ac826 commit dc4b3cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_butler_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def x_remove(self, name: str) -> None:
------
lsst.daf.butler.registry.MissingCollectionError
Raised if no collection with the given name exists.
sqlalchemy.exc.IntegrityError
lsst.daf.butler.registry.OrphanedRecordError
Raised if the database rows associated with the collection are
still referenced by some other table, such as a dataset in a
datastore (for `~CollectionType.RUN` collections only) or a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@

from collections.abc import Iterable, Sequence, Set

import sqlalchemy
from lsst.utils.iteration import ensure_iterable

from .._butler_collections import ButlerCollections, CollectionInfo
from .._collection_type import CollectionType
from ..registry._exceptions import OrphanedRecordError
from ..registry.interfaces import ChainedCollectionRecord
from ..registry.sql_registry import SqlRegistry

Expand Down Expand Up @@ -151,4 +153,7 @@ def register(self, name: str, type: CollectionType = CollectionType.RUN, doc: st
return self._registry.registerCollection(name, type, doc)

def x_remove(self, name: str) -> None:
self._registry.removeCollection(name)
try:
self._registry.removeCollection(name)
except sqlalchemy.exc.IntegrityError as e:
raise OrphanedRecordError(f"Datasets in run {name} are still referenced elsewhere.") from e

Check warning on line 159 in python/lsst/daf/butler/direct_butler/_direct_butler_collections.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/direct_butler/_direct_butler_collections.py#L158-L159

Added lines #L158 - L159 were not covered by tests

0 comments on commit dc4b3cb

Please sign in to comment.