Closed mpetazzoni closed 3 months ago
Thanks. Can I ask what prompted this? I thought most python DB libraries close the connection when the handle leaves scope/is deleted.
@tconbeer Thanks for taking a look! Python does not guarantee that the __del__
finalizer gets called on interpreter exit, and since the Harlequin app keeps a reference to it (self.connection
), nor does it use a context manager for the connection object around the lifecycle of the Harlequin app, there is no current possible mechanism for an adapter to perform a graceful shutdown/close of its connection to the database.
Of course, connections are severed when Python exists, but there might situations where adapters want to perform on-shutdown actions (flush, commit, emit telemetry, or gracefully release resources). This new close()
method gives them an opportunity to do so, if they want to. See for example the DB-API spec.
ok, I'm on-board. thanks for the extra info, makes sense.
This change introduces a new optional method of HarlequinConnection implementations in adapters, giving them an opportunity to cleanly close the connection to the underlying database when the app exists.
The
close()
method is called in theaction_quit()
handler.Does this PR require a change to Harlequin's docs?
HarlequinConnection.close()
can be documented in the "Creating an Adapter" guide.Did you add or update tests for this change?
Please complete the following checklist:
CHANGELOG.md
, under the[Unreleased]
section heading. That entry references the issue closed by this PR.