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

Calling mogrify on closed cursor #579

drtyrsa opened this Issue Aug 2, 2017 · 1 comment


None yet
2 participants

drtyrsa commented Aug 2, 2017

Currently it's impossible to call mogrify on closed cursor. Is it really necessary? It seems that mogrifying is done on client side and doesn't use DB server, so it shouldn't care whether cursor is closed or not.

The context where it's relevant is logging sql on exception:

    cursor.execute(sql, params)
except psycopg2.Error:
    logger.exception('Database error when executing %s', cursor.mogrify(sql, params))

If cursor is somehow closed it's impossible to log final sql query.


This comment has been minimized.


dvarrazzo commented Aug 2, 2017

Maybe the test is eccessive, but maybe some adapter will call some libpq function that may fail if the connection is close - especially I think about escaping strings. We can take a look.

@dvarrazzo dvarrazzo added this to the psycopg 2.7.4 milestone Nov 13, 2017

dvarrazzo added a commit that referenced this issue Jan 10, 2018

dvarrazzo added a commit that referenced this issue Jan 10, 2018

@dvarrazzo dvarrazzo closed this in e0226fc Jan 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment