django-debug-toolbar
django-debug-toolbar copied to clipboard
SQL queries shown without bound variables
Given a Django code:
Boo.objects.filter(foo__icontains="moo")
that produces (approx.) this SQL query:
SELECT * FROM boo WHERE UPPER(foo) LIKE UPPER('%moo%')
the debug toolbar shows this query:
SELECT * FROM boo WHERE UPPER(foo) LIKE UPPER(' ')
So the query in the toolbar is missing the searched string ('moo'). Curiously enough, when I had django print me the query like so: print(qs.query), the toolbar suddenly started to show the values correctly. When the print was removed, values disappeared again.
| version | |
|---|---|
| Django | 3.0.2 |
| Python | 3.7.2 |
| Debug Toolbar | 2.2 |
I'm unable to reproduce this. Running the example app and browsing out to http://127.0.0.1:8000/admin/auth/user/?username__icontains=moo generates this query:
SELECT ••• FROM "auth_user" WHERE "auth_user"."username" LIKE '''%moo%''' ESCAPE '\'
Right. Sorry. I think the culprit is an annotate clause. Once I add that, the values disappear (from WHERE):
qs.annotate(abc=Concat("foo", Value(" "), "foo2"))
Can you give me the full queryset that's problematic?
I am not at liberty to post the thing as-is, so I will create a clean install of django and produce a minimal failing scenario.
That's even better.
Closing due to lack of response.