From e7566826e0ea9394e91a385bb4a255977ff83aeb Mon Sep 17 00:00:00 2001 From: Evan <93949832+Exu-112@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:23:12 -0400 Subject: [PATCH] fixes to error message logic --- simple/utils/astrometry.py | 4 ++-- tests/test_astrometry.py | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/simple/utils/astrometry.py b/simple/utils/astrometry.py index 02783b344..15a22ac1e 100644 --- a/simple/utils/astrometry.py +++ b/simple/utils/astrometry.py @@ -299,14 +299,14 @@ def ingest_parallax( session.commit() logger.info(f" Photometry added to database: {parallax_data}\n") except sqlalchemy.exc.IntegrityError as e: + msg = ( "The source may not exist in Sources table.\n" "The parallax reference may not exist in Publications table. " "Add it with add_publication function. \n" - "The parallax measurement may be a duplicate." ) if raise_error: - raise AstroDBError(msg) from e + raise AstroDBError(e) else: logger.warning(msg) diff --git a/tests/test_astrometry.py b/tests/test_astrometry.py index 1f79c0b8f..6a607ff51 100644 --- a/tests/test_astrometry.py +++ b/tests/test_astrometry.py @@ -101,13 +101,11 @@ def test_ingest_parallaxes(temp_db, t_plx): def test_parallax_exceptions(temp_db): with pytest.raises(AstroDBError) as error_message: ingest_parallax(temp_db, "bad source", 1, 1, "Ref 1") - assert "The source may not exist in Sources table" in str(error_message.value) + assert "FOREIGN KEY constraint failed" in str(error_message.value) with pytest.raises(AstroDBError) as error_message: ingest_parallax(temp_db, "Fake 1", 1, 1, "bad ref") - assert "The parallax reference may not exist in Publications table" in str( - error_message.value - ) + assert "FOREIGN KEY constraint failed" in str(error_message.value) ingest_parallax(temp_db, "Fake 2", 1, 1, "Ref 2") with pytest.raises(AstroDBError) as error_message: