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

Patch CursorWrapper dynamically to allow multiple base classes. #1820

Merged
merged 4 commits into from
Aug 11, 2023

Conversation

tim-schilling
Copy link
Member

When the debug SQL logs are enabled, the wrapper class is CursorDebugWrapper not CursorWrapper. Since we have inspections based on that specific class they are removing the CursorDebugWrapper causing the SQL logs to not appear.

This attempts to dynamically patch the CursorWrapper or CursorDebugWrapper with the functionality we need.

This doesn't do a full regression test, but it may be possible to get it to work with:

TEST_ARGS='--debug-sql' make test

Which causes the current set of tests to fail since they are keyed to CursorWrapper.

Fixes #1814

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

When the debug SQL logs are enabled, the wrapper class is CursorDebugWrapper
not CursorWrapper. Since we have inspections based on that specific class
they are removing the CursorDebugWrapper causing the SQL logs to not appear.

This attempts to dynamically patch the CursorWrapper or CursorDebugWrapper
with the functionality we need.

This doesn't do a full regression test, but it may be possible to get
it to work with:

    TEST_ARGS='--debug-sql' make test

Which causes the current set of tests to fail since they are keyed to
CursorWrapper.
@tim-schilling tim-schilling requested a review from matthiask August 3, 2023 12:30
@tim-schilling
Copy link
Member Author

@living180 I can't add you to the requested reviewers, but I'd appreciate you taking a look at this PR.

Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@tim-schilling
Copy link
Member Author

@matthiask sorry, can you review that last commit too. It's a bit of a hack, but it's either that or inspecting self._outcome.results to determine if the test is running with the debug sql option.

@tim-schilling
Copy link
Member Author

I'm likely to cut a release after this PR.

@matthiask
Copy link
Member

@matthiask sorry, can you review that last commit too. It's a bit of a hack, but it's either that or inspecting self._outcome.results to determine if the test is running with the debug sql option.

Thanks, I think the way it's implemented makes sense!

@living180
Copy link
Contributor

Didn't have time to review this until just now, but the implementation looks good and a basic smoke test passes for me. The only improvement I'd suggest would be a bit of bike-shedding by renaming NormalCursorWrapper and ExceptionCursorWrapper and NormalCursorMixin and ExceptionCursorMixin, respectively, but that's just a matter of taste.

@tim-schilling
Copy link
Member Author

Good enough for me.

@tim-schilling tim-schilling merged commit 7677183 into django-commons:main Aug 11, 2023
@tim-schilling tim-schilling deleted the sql-logging branch August 11, 2023 01:20
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.

Django logging not working when djdt is enabled
3 participants