pepkit / pepdbagent

Database for storing sample metadata
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

More descriptive error for lack of connection `'BaseConnection' object has no attribute 'pg_connection'` #77

Closed nleroy917 closed 1 year ago

nleroy917 commented 1 year ago

An error I see nearly everyone run into when deploying pephub on their own is this one:

psycopg2.OperationalError: could not translate host name "localhost:5432" to address: Name or service not know
AttributeError: 'BaseConnection' object has no attribute 'pg_connection'

It comes from pepdbagent, and occurs when people have improperly configured their environment to connect to the database (i.e. the database connection credentials are wrong/not injected). It looks like pepdbagent is trying to close a connection when it can't connect. When the object is garbage collected away here there is no connection to close.

Anyways, it sort of masks the real error that's occurring and so it would be nice if we could include some checks since it seems like this is a bug that trips up many, many people:

  1. Check for a connection object before closing in the garbage collection
  2. Check that the provided credentials actually connect and raise an exception if not.
khoroshevskyi commented 1 year ago

Fixed in v0.4.0 since pepdbagent was witched to SQLAlchemy ORM.