-
-
Notifications
You must be signed in to change notification settings - Fork 339
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
Consider using Django 2.0 execute_wrapper()
#214
Comments
@shaib If you have the time I encourage you to make a PR with this enhancement. I can take a look and merge it in. |
Coming from #630 IssueI've tracked down the issue to Method 1: Keep patchingKeep patching the compilers, I've tried to patch all 5 compilers:
but this leads to either recursion errors (because of a
Method 2: Wrap the cursor, not the compilerI took a look at how Method 3: Add a db wrapper on the connection for the requestAs @shaib mentioned, it is possible to wrap cleanly (since Django 2.0) SQL queries, through a context manager, in the middleware for example: class SilkyMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
self.process_request(request)
query_logger = SilkyQueryLogger()
with connection.execute_wrapper(qquery_logger):
response = self.get_response(request)
return self.process_response(request, response) This is the cleanest way to log queries, and supported through official API. As in method 2, we don't have access to query model context. Method 4: Add a permanent db wrapper on the connection in
|
This would be awesome. I have several celery jobs, management commands, and other non-API contexts where I'd love to get the data I get from django-silk. As a temporary workaround, I found this GitHub gist that you can use to run django-silk against arbitrary functions not wrapped in APIs. It would be fantastic to see something supported by django-silk in the future. |
Silk currently uses monkeypatching to install its wrapper around
SQLCompiler.execute_sql
. Django 2.0 provides a new API for installing wrappers around SQL executions, and it may be preferable to use this API when available.Points arising:
SQLCompiler
. I'm not sure what the implications are.hasattr(connection, 'execute_wrapper')
.The text was updated successfully, but these errors were encountered: