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

Disabled autocommit on select #116

Closed
obensonne opened this issue Oct 11, 2012 · 3 comments
Closed

Disabled autocommit on select #116

obensonne opened this issue Oct 11, 2012 · 3 comments

Comments

@obensonne
Copy link

The Database.execute_sql() considers 2 parameters when deciding if to do a commit after executing a statement:

def execute_sql(self, sql, params=None, require_commit=True):
    cursor = self.get_cursor()
    res = cursor.execute(sql, params or ())
    if require_commit and self.get_autocommit():
        self.commit()
    logger.debug((sql, params))
    return cursor

Two issues:

  1. Shouldn't the condition be or-ed? At least the wording require suggests this.
  2. If no, why does a SelectQuery has set require_commit = False?

A continously running application which only does selects opens a transaction once and keeps it open forever (tested with PostgreSQL).

Looks like a bug, isn't it?

@coleifer
Copy link
Owner

My thinking was that we should only explicitly commit when, first of all, it is warranted (by being a query that writes something) and second of all, that the commit isn't being managed elsewhere.

I am not aware of the need to open a transaction when doing SELECTs. That seems odd -- can you provide a little more info?

coleifer added a commit that referenced this issue Oct 12, 2012
autocommit mode, will open a transaction for any query, including
selects.  If not comitted, leads to idle in transactions -- this fixes
and also addresses #116
@coleifer
Copy link
Owner

Thanks for reporting -- i didn't realize that psycopg2, as you said, opens a transaction every query. This should be fixed now, and select queries will have their transactions handled correctly

@obensonne
Copy link
Author

Great, thanks for the quick fix!

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