Skip to content

Commit

Permalink
Do nothing if there are no Objects to write
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Mar 13, 2024
1 parent cc2b57d commit ecd74a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/lsst/dax/apdb/apdbSql.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,10 @@ def _storeDiaObjects(
insert_id : `ApdbInsertId`
Insert identifier.
"""
if len(objs) == 0:
_LOG.info("No objects to write to database.")
return

# Some types like np.int64 can cause issues with sqlalchemy, convert
# them to int.
ids = sorted(int(oid) for oid in objs["diaObjectId"])
Expand Down
15 changes: 15 additions & 0 deletions python/lsst/dax/apdb/tests/_apdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,21 @@ def test_storeObjects(self) -> None:

# TODO: test apdb.contains with generic implementation from DM-41671

def test_storeObjects_empty(self) -> None:
"""Test calling storeObject when there are no objects: see DM-43270.
"""
config = self.make_config()
Apdb.makeSchema(config)
apdb = make_apdb(config)
region = _make_region()
visit_time = self.visit_time
# make catalog with no Objects
catalog = makeObjectCatalog(region, 0, visit_time)

with self.assertLogs("lsst.dax.apdb.apdbSql", level="INFO") as cm:
apdb.store(visit_time, catalog)
self.assertIn("No objects", "\n".join(cm.output))

def test_storeSources(self) -> None:
"""Store and retrieve DiaSources."""
config = self.make_config()
Expand Down

0 comments on commit ecd74a8

Please sign in to comment.