Skip to content

Commit

Permalink
fixes to error message logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Exu-112 committed Jul 2, 2024
1 parent e0d43fd commit e756682
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions simple/utils/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions tests/test_astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e756682

Please sign in to comment.