Skip to content

Remove the query logger when the query_logger() block raises - #1373

Open
kratos0718 wants to merge 1 commit into
MagicStack:masterfrom
kratos0718:fix-query-logger-on-error
Open

kratos0718 wants to merge 1 commit into
MagicStack:masterfrom
kratos0718:fix-query-logger-on-error

Conversation

@kratos0718

Copy link
Copy Markdown

Connection.query_logger() removed its callback after a bare yield, so if anything inside the with block raises, for example a query that fails, the callback stays registered on the connection. With a pool, that connection is handed to other code later and the logger keeps receiving those unrelated queries, and it is never released.

The fix moves remove_query_logger() into a finally. I added test_logging_context_removed_on_error to tests/test_logging.py. It fails on master with the logger still attached (1 != 0) and passes with the change. tests.test_logging and flake8 pass locally.

query_logger() removed its callback after a bare yield, so any exception
in the with-block, such as a failing query, left the logger attached to
the connection. Pooled connections then kept reporting later, unrelated
queries to it.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant