Skip to content

Commit 6b83106

Browse files
committed
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: #1130 Fixes: #423
1 parent 6fae2a9 commit 6b83106

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
@@ -137,6 +137,14 @@ def _decode(self, param):
137137
def _record(self, method, sql, params):
138138
start_time = time()
139139
try:
140+
if isinstance(params, list):
141+
142+
def strip_GeomFromEWKB(param):
143+
if isinstance(param, str):
144+
return param.lstrip("ST_GeomFromEWKB('\\x").rstrip("'::bytea)")
145+
return param
146+
147+
params = [strip_GeomFromEWKB(param) for param in params]
140148
return method(sql, params)
141149
finally:
142150
stop_time = time()

0 commit comments

Comments
 (0)