Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ def __call__(self, execute, sql, params, many, context):

sql = add_sql_comment(
sql,
# For supported tags, see: https://cloud.google.com/sql/docs/mysql/using-query-insights#using-sql-commenter
# Information about the controller.
controller=resolver_match.view_name if resolver_match and with_controller else None,
# route is the pattern that matched a request with a controller i.e. the regex
# See https://docs.djangoproject.com/en/stable/ref/urlresolvers/#django.urls.ResolverMatch.route
# getattr() because the attribute doesn't exist in Django < 2.2.
route=getattr(resolver_match, 'route', None) if resolver_match and with_route else None,
# app_name is the application namespace for the URL pattern that matches the URL.
# application is the application namespace for the URL pattern that matches the URL.
# See https://docs.djangoproject.com/en/stable/ref/urlresolvers/#django.urls.ResolverMatch.app_name
app_name=(resolver_match.app_name or None) if resolver_match and with_app_name else None,
application=(resolver_match.app_name or None) if resolver_match and with_app_name else None,
# Framework centric information.
framework=('django:%s' % django_version) if with_framework else None,
# Information about the database and driver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def __call__(self, scope, receive, send):
def _get_fastapi_info(fastapi_app: FastAPI, scope) -> dict:
info = {
"framework": 'fastapi:%s' % fastapi.__version__,
"app_name": fastapi_app.title,
"application": fastapi_app.title,
}

route = _get_fastapi_route(fastapi_app, scope)
Expand Down
6 changes: 3 additions & 3 deletions python/sqlcommenter-python/tests/django/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ def test_non_root_path(self):
def test_app_path(self):
with self.settings(SQLCOMMENTER_WITH_APP_NAME=True):
query = self.get_query(path=reverse('app_urls:app-path'))
self.assertIn("/*app_name='app_urls'", query)
self.assertIn("/*application='app_urls'", query)
self.assertIn("controller='app_urls%%3Aapp-path'", query)
self.assertRoute('app-urls/app-path/', query)

def test_app_name_disabled(self):
query = self.get_query(path=reverse('app_urls:app-path'))
self.assertNotIn('app_name=', query)
self.assertNotIn('application=', query)

def test_empty_app_name(self):
"""An empty app_name is omitted."""
with self.settings(SQLCOMMENTER_WITH_APP_NAME=True):
query = self.get_query()
self.assertNotIn("app_name=", query)
self.assertNotIn("application=", query)

def test_db_driver(self):
with self.settings(SQLCOMMENTER_WITH_DB_DRIVER=True):
Expand Down
4 changes: 2 additions & 2 deletions python/sqlcommenter-python/tests/fastapi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def client():

def test_get_fastapi_info_in_request_context(client):
expected = {
'app_name': 'SQLCommenter',
'application': 'SQLCommenter',
'controller': 'fastapi_info',
'framework': 'fastapi:%s' % fastapi.__version__,
'route': '/fastapi-info',
Expand All @@ -43,7 +43,7 @@ def test_get_fastapi_info_in_request_context(client):

def test_get_fastapi_info_in_404_error_context(client):
expected = {
'app_name': 'SQLCommenter',
'application': 'SQLCommenter',
'framework': 'fastapi:%s' % fastapi.__version__,
}
resp = client.get('/doesnt-exist')
Expand Down