-
Notifications
You must be signed in to change notification settings - Fork 14
Make RequestLoggingMiddleware async capable #41
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
Open
browniebroke
wants to merge
1
commit into
namespace-ee:main
Choose a base branch
from
browniebroke:feat/async-request-logging-middleware
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
JSON-log-formatter | ||
Django | ||
asgiref | ||
djangorestframework | ||
backports.zoneinfo;python_version<"3.9" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add async test coverage.
Your asynchronous dunder call method mirrors the sync flow, ensuring that logging is captured. However, it would be beneficial to add unit tests (or integration tests) specifically covering the async path to confirm it handles exceptions, logging, and response attributes as expected.
I'd be happy to provide a test snippet or open a follow-up issue to ensure this new async functionality is thoroughly verified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
I'll create a comprehensive test snippet for the async middleware functionality. First, let me explore the codebase to understand the existing test structure and patterns.
Let me also examine the specific structure of the existing tests for the middleware component:
Let me also check if Django, pytest-asyncio, or other async testing tools are already in the project dependencies:
Now let me understand how Django is configured in this project, particularly regarding middleware settings:
Let me check for any existing test utilities or fixtures that might be useful:
Based on the information gathered, I'll now craft a proper async test snippet for the RequestLoggingMiddleware class.
@lnagel, here's a test snippet that covers the async capability of the
RequestLoggingMiddleware
:To run these tests, you'll need to add
pytest-asyncio
to your test dependencies:Some notes about the test implementation:
The tests cover three main scenarios:
get_response
functionsI've used
AsyncRequestFactory
from Django's test utilities to create async-compatible requests.The tests use both
unittest
style (through Django'sTestCase
) and pytest-asyncio marker for async test functions.Each test verifies both the response handling and the logging behavior, ensuring that the async path correctly logs responses with the right log level and includes all expected metadata.
If you'd like, I can also prepare a follow-up issue to track this test implementation. Would you prefer I do that as well?
🏁 Script executed:
Length of output: 740
🏁 Script executed:
Length of output: 252
🏁 Script executed:
Length of output: 2146
🏁 Script executed:
Length of output: 283
🏁 Script executed:
Length of output: 304
@lnagel Sure, here's a comprehensive test implementation for the async capability of
RequestLoggingMiddleware
:This test suite:
Uses Django's
TestCase
to match the existing codebase style rather than pytestTests all key components of the async middleware functionality:
Uses
asyncio.run()
to execute the async methods in a unittest environment, which doesn't natively support async testsMocks the logger to verify the correct log level and message content
Let me know if you need any adjustments to this test implementation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you interested in adding these tests? Let me know if I should add anything else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning on adding them after the merge