Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message when element not found #141

Closed
Vi-L opened this issue Mar 30, 2024 · 1 comment · Fixed by #142
Closed

Confusing error message when element not found #141

Vi-L opened this issue Mar 30, 2024 · 1 comment · Fixed by #142
Labels
bug Something isn't working

Comments

@Vi-L
Copy link
Contributor

Vi-L commented Mar 30, 2024

Describe the bug

When an element is not found, a confusing sqlalchemy error is raised.

To Reproduce

Steps to reproduce the behavior:

>>> import mendeleev
>>> mendeleev.element("si")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/g/.local/lib/python3.10/site-packages/mendeleev/mendeleev.py", line 64, in element
    return _get_element(ids)
  File "/home/g/.local/lib/python3.10/site-packages/mendeleev/mendeleev.py", line 81, in _get_element
    return session.query(Element).filter(Element.symbol == str(ids)).one()
  File "/home/g/.local/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2797, in one
    return self._iter().one()  # type: ignore
  File "/home/g/.local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1827, in one
    return self._only_one_row(
  File "/home/g/.local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 760, in _only_one_row
    raise exc.NoResultFound(
sqlalchemy.exc.NoResultFound: No row was found when one was require

Expected behavior

A clear error message saying that the element was not found, without showing sqlalchemy, which is an implementation detail.

Specification

  • mendleev 0.15.0
  • python 3.10
  • Windows 10

Additional context

See this post.

@Vi-L Vi-L added the bug Something isn't working label Mar 30, 2024
@lmmentel
Copy link
Owner

Thanks for reporting this @Vi-L . Indeed the error message can be quite confusing. It comes straight from SQLAlchemy but that's not a detail that needs to be exposed to end users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants