This project is archived and is in readonly mode.
connection.status is equal to STATUS_READY even when connection is closed
-
Daniele Varrazzo
Well, it's just that the status is no more updated after the connection is closed. We don't even have a STATUS_CLOSED. So we could say that's the "status of the connection when it's working, otherwise it's undefined". I'll write a line in the docs about that.
-
Agniva De Sarkar
thank you. On another note, how difficult is it to have a STATUS_CLOSED or STATUS_UNHEALTHY for a connection ? I came across this bug because I needed to write a reconnect function and for that I needed to verify whether the existing connection is good or bad.
-
Daniele Varrazzo
It is complicated and it is a duplication of other attributes. Now I'm fixing the bugs with the current statuses but I don't want to introduce more.
The most reliable way to get the state of the connection is to call get_transaction_status() that will query the underlying connection instead of being a psycopg status. Note that until the currently released version of psycopg you cannot call that function when the connection is closed: this is not necessary as the underlying libpq function is local: starting from next version it will be possible to call it on closed connection too (it would probably return "unknown").
So for now: check closed, if not closed check
get_transaction_status(). This should be reliable. -
Daniele Varrazzo
- State changed from new to resolved
Documentation clarified, but there will be no change in the attribute behaviour.
http://initd.org/psycopg/docs/connection.html#connection.status