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

Using ISOLATION_LEVEL_AUTOCOMMIT in connection.set_session results in error #310

Closed
kitterma opened this issue Apr 24, 2015 · 2 comments
Closed
Milestone

Comments

@kitterma
Copy link

The following was reported against 2.5.4 by a Debian user. I've inspected the code in 2.6 and it's the same.

Subject: [python-psycopg2] extensions.ISOLATION_LEVEL_AUTOCOMMIT should disappear

Or at the very least, doc should clearly state that it MUST NOT
be used into 'set_session()')'.

Because issuing:
connection.set_session(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT,
readonly=True, deferrable=False, autocommit=True)

fails with the following message:
ValueError: isolation_level must be between 1 and 4
(œuf corse, as psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT == 0)

I did look at the code that triggers this, psycopg/connection_type.c line 460 in 2.6, and I think it should be:

if (level < 0 || level > 4) {

and the error message two lines later adjusted as well. It looks like this code was added in:

ea03ffb

and then never revisited. That said, I'm not that familiar with it and autocommit may not be appropriate here, in which case the documentation should be updated to mention this.

@dvarrazzo
Copy link
Member

extensions.ISOLATION_LEVEL_AUTOCOMMIT cannot disappear because it is used by the older method set_isolation_level. It has never meant to be supported as isolation_level by set_session() (it is not an isolation level and most definitely not used by the server: it only changes the client-side behaviour of the connection).

We will improve the docs for set_session() making clear that only the other constants are accepted for the parameter. Thank you for the report.

@dvarrazzo dvarrazzo added this to the psycopg 2.6.1 milestone Apr 24, 2015
@dvarrazzo
Copy link
Member

(note to me: the concept that only the specified parameters are changed is currently written twice in the method docs: fix it)

dvarrazzo added a commit that referenced this issue May 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants