django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

SQL queries shown without bound variables

Open PunchyRascal opened this issue 5 years ago • 5 comments

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

PunchyRascal avatar Feb 05 '20 17:02 PunchyRascal

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 '\'

tim-schilling avatar Feb 05 '20 21:02 tim-schilling

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"))

PunchyRascal avatar Feb 06 '20 09:02 PunchyRascal

Can you give me the full queryset that's problematic?

tim-schilling avatar Feb 06 '20 15:02 tim-schilling

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.

PunchyRascal avatar Feb 07 '20 08:02 PunchyRascal

That's even better.

tim-schilling avatar Feb 07 '20 15:02 tim-schilling

Closing due to lack of response.

tim-schilling avatar Aug 29 '22 02:08 tim-schilling