Remove duplicate query logging that breaks Django's assertNumQueries#4367
Conversation
3f6ab47 to
14a2c7e
Compare
14a2c7e to
5b94cb1
Compare
|
Thanks for catching this! Could unit test coverage be added here on OTel Contrib side? Maybe it could borrow from your other-project test case that does the |
|
@tammy-baylis-swi I tried but found it hard to come up with a meaningful test that it does NOT mess with the query log. Could be something like this, but still feels a bit artificial: connection = MagicMock()
connection.queries_log = deque()
connection.force_debug_cursor = False
with CaptureQueriesContext(connection) as ctx:
qw_instance = _QueryWrapper(requests_mock)
execute_mock = MagicMock()
context = {"cursor": MagicMock(), "connection": connection}
qw_instance(
execute_mock, "SELECT 1", MagicMock(), MagicMock(), context
)
self.assertEqual(len(ctx), 0) |
Agree that it's quite mock-y @federicobond , which reminds me that we've been wanting to add proper db client testing for a while but haven't gotten to it with all else going on: #3032 Maybe a quick unit test is better than nothing for now? Would be good to get other Approvers' thoughts. |
|
I'm not sure it's worth it to add a test here to be honest. There was never a test for the original query log behavior to begin with. |
b9af128 to
52e0fd4
Compare
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
|
This issue is still relevant. Pull request is just waiting for a second approval |
|
Maintainers, please have a look. |
|
Thanks for the PR! Just a heads-up: we no longer update Please add the appropriate changelog fragment for this change instead of editing |
The SqlCommenter _QueryWrapper manually appends the SQL string to queries_log when a CursorDebugWrapper is active. However, CursorDebugWrapper.debug_sql already logs the query as a dict with "sql" and "time" keys. This causes two problems: 1. Queries are double-counted in queries_log 2. The raw string entries cause a TypeError in Django's assertNumQueries, which expects dict entries with a "sql" key Remove the manual append and let Django handle query logging.
52e0fd4 to
e1d3647
Compare
|
Done, let me know if I've correctly added the changelog entry. |
f918859
The SqlCommenter _QueryWrapper manually appends the SQL string to queries_log when a CursorDebugWrapper is active. However, CursorDebugWrapper.debug_sql already logs the query as a dict with "sql" and "time" keys. This causes two problems:
Remove the manual append and let Django handle query logging.
Type of change
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.