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

Update EasyAuditMiddleware to support async context #292

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

KaczuH
Copy link

@KaczuH KaczuH commented Apr 20, 2024

Replaced standard threading with 'asgiref.local' in EasyAuditMiddleware. Also, made EasyAuditMiddleware extend Django's MiddlewareMixin to automatically handle sync and async execution modes. Github issue: #291

Replaced standard threading with 'asgiref.local' in EasyAuditMiddleware. Also, made EasyAuditMiddleware extend Django's MiddlewareMixin to automatically handle sync and async execution modes.
Github issue: soynatan#291
easyaudit/middleware/easyaudit.py Outdated Show resolved Hide resolved
Kamil Niski added 3 commits April 25, 2024 09:33
The EasyAuditMiddleware class has been updated to be compatible with both synchronous and asynchronous processes. The class initialization now checks if the 'get_response' function is a coroutine and sets the class' async capability accordingly. An '__acall__' method has been introduced to handle asynchronous calls.
Replaced sync_to_async keyword usage throughout the test_main.py file with direct asyncio calls, specifically in the ASGIRequestEvent tests. This change both simplifies the code and reduces reliance on the sync_to_async function.
A new test has been added to verify the async capability of the EasyAuditMiddleware. This ensures that the Django logger does not emit a debug message for asynchronous handler adaptation for the middleware. This is aligned with the Django documentation recommendations on async views.
@KaczuH KaczuH requested a review from samamorgan April 27, 2024 01:12
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.

None yet

2 participants