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
Connection.runInteraction() may not close cursor? #35
Comments
Ah, you're right, it's not closing the cursor in case of an error. I don't think the last Good catch, will fix. |
Thanks for the report, I made the docs clearer on that and made sure the cursor is always closed. Oh, and turned out you were right, it should have been |
Beware that this probably broke disconnecting during interaction execution, see #37 for how fixing runQuery() this way broke the disconnectWhileRunning test. |
The only reason for closing a psycopg2 cursor is to prevent its further usage. Cursors created internally when using runQuery and runOperation are never surfaced to the user, so there's no need to explicitly close them. Issue #35 spurred an effort to make sure all generated cursors are always closed, but it now seems that it's not the right way to go about the problem. There's no benefit to forcing psycopg2 cursors to be closed and if the cursor (or connection) are in a bad state, it risks throwing suprious errors. Leave it to psycopg2 to deal with cursors going away and simply fix runInteraction's docstring to explicitly say that the user should not close the cursor they got passed.
I just read through the source for
runInteraction()
since the documentation left me wondering whether I was supposed to manually close the cursor in the supplied function. (Apparently not.)If I'm reading this right,
rollbackAndPassthrough()
will always return a Failure, causing the callback that closes the cursor to never be called since the errback will be called instead? Shouldn't it beaddBoth()
instead ofaddCallback()
for thec.close()
lambda? Or am I missing something?The text was updated successfully, but these errors were encountered: