Skip to content

Commit

Permalink
support for list params in query preview
Browse files Browse the repository at this point in the history
  • Loading branch information
morlandi committed Mar 15, 2024
1 parent 607db6e commit fd37c67
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
History
=======

v1.2.8
------
- support for list params in query preview

v1.2.7
------
- improved `prettyprint_query()`
Expand Down
11 changes: 11 additions & 0 deletions query_inspector/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import traceback
import json
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.contrib import admin
Expand Down Expand Up @@ -128,6 +129,16 @@ def preview(self, request, object_id):
for parameter in parameters
}

# Adjust list parameters
# Es: "['my', 'id']" --> ['my', 'id']
# this is a rather weak solution which we might improve sooner or later
# Working use case:
# params = {'countries': "['my', 'id']"}
# sql = " ... WHERE lower(C.code) = ANY( %(countries)s )"
for key, value in params.items():
if value.startswith('[') and value.endswith(']'):
params[key] = json.loads(value.replace('\'', '"'))

# Load default parameters
if request.method =="GET":
for key, value in params.items():
Expand Down
2 changes: 1 addition & 1 deletion query_inspector/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def escape(v):
sql = _str_query(query.replace('\n', ' '), params).strip()
print(sql)
if params is not None:
trace('params[]: ' + str(params), color='black', on_color='on_white')
trace('params: ' + str(params), color='light_grey')
print("-" * 80)


Expand Down

0 comments on commit fd37c67

Please sign in to comment.