Skip to content

Commit 5510859

Browse files
committed
Added support to filter queries based on regex patterns
1 parent 5d8abcf commit 5510859

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

devserver/modules/sql.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ def execute(self, sql, params=()):
6161
formatted_sql = sql % (params if isinstance(params, dict) else tuple(params))
6262
if self.logger:
6363
message = formatted_sql
64-
if settings.DEVSERVER_TRUNCATE_SQL:
65-
message = truncate_sql(message, aggregates=settings.DEVSERVER_TRUNCATE_AGGREGATES)
66-
message = sqlparse.format(message, reindent=True, keyword_case='upper')
67-
self.logger.debug(message)
64+
if settings.DEVSERVER_FILTER_SQL:
65+
if any(filter_.search(message) for filter_ in settings.DEVSERVER_FILTER_SQL):
66+
message = None
67+
if message is not None:
68+
if settings.DEVSERVER_TRUNCATE_SQL:
69+
message = truncate_sql(message, aggregates=settings.DEVSERVER_TRUNCATE_AGGREGATES)
70+
message = sqlparse.format(message, reindent=True, keyword_case='upper')
71+
self.logger.debug(message)
6872

6973
start = datetime.now()
7074

devserver/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# 'devserver.modules.cache.CacheSummaryModule',
1111
))
1212

13+
DEVSERVER_FILTER_SQL = getattr(settings, 'DEVSERVER_FILTER_SQL', False)
1314
DEVSERVER_TRUNCATE_SQL = getattr(settings, 'DEVSERVER_TRUNCATE_SQL', True)
1415

1516
DEVSERVER_TRUNCATE_AGGREGATES = getattr(settings, 'DEVSERVER_TRUNCATE_AGGREGATES', getattr(settings, 'DEVSERVER_TRUNCATE_AGGREGATES', False))

0 commit comments

Comments
 (0)