Skip to content

Commit bf1bfa1

Browse files
authored
Fix SQL selected / SQL explain for gis queries
Without this fix, pushing the 'sel' or 'explain' button for a query containing some EWKB-encoded geometry as parameter results in this crash: ``` Internal Server Error: /__debug__/sql_explain/ Traceback (most recent call last): File "/Users/jieter/.pyenv/versions/obs/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) psycopg2.errors.InternalError_: parse error - invalid geometry LINE 1: ...ure" IN (0, 1, 5)) AND "waarneming"."geo_point" @ 'ST_GeomFr... ^ HINT: "ST" <-- parse error at position 2 within geometry ``` I'm not sure if this is the appropriate location in the code, but with this fix, both `sql_select` and `sql_explain` work without flaws. Previous PR adding a similar fix: django-commons#1130 Fixes: django-commons#423
1 parent 176614a commit bf1bfa1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

debug_toolbar/panels/sql/tracking.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ def _decode(self, param):
130130
def _record(self, method, sql, params):
131131
start_time = time()
132132
try:
133+
if isinstance(params, list):
134+
135+
def strip_GeomFromEWKB(param):
136+
if isinstance(param, str):
137+
return param.lstrip("ST_GeomFromEWKB('\\x").rstrip("'::bytea)")
138+
return param
139+
140+
params = [strip_GeomFromEWKB(param) for param in params]
133141
return method(sql, params)
134142
finally:
135143
stop_time = time()

0 commit comments

Comments
 (0)