Skip to content

Commit c2a9041

Browse files
committed
Revert PR 1426 - PostGIS param stripping.
The stripping logic is stripping general sql parameters and the test written for it does not run. I'm not confident that the test actually hits the code we expect it to run either. Closes #1543 Reopens #423
1 parent 69506fb commit c2a9041

File tree

6 files changed

+13
-36
lines changed

6 files changed

+13
-36
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ jobs:
8282
max-parallel: 5
8383
matrix:
8484
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
85+
database: [postgresql, postgis]
8586

8687
services:
8788
postgres:
88-
image: postgres
89+
image: postgis/postgis:14-3.1
8990
env:
9091
POSTGRES_DB: debug_toolbar
9192
POSTGRES_USER: debug_toolbar
@@ -133,7 +134,7 @@ jobs:
133134
- name: Test with tox
134135
run: tox
135136
env:
136-
DB_BACKEND: postgresql
137+
DB_BACKEND: ${{ matrix.database }}
137138
DB_HOST: localhost
138139
DB_PORT: 5432
139140

debug_toolbar/panels/sql/tracking.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ 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]
148140
return method(sql, params)
149141
finally:
150142
stop_time = time()

docs/changes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Change log
44
Next version
55
------------
66

7+
* Revert PR 1426 - Fixes issue with SQL parameters having leading and
8+
trailing characters stripped away.
9+
710
3.2.3 (2021-12-12)
811
------------------
912

tests/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"tests",
2828
]
2929

30-
USE_GIS = os.getenv("DB_BACKEND") in ("postgis",)
30+
USE_GIS = os.getenv("DB_BACKEND") == "postgis"
3131

3232
if USE_GIS:
3333
INSTALLED_APPS = ["django.contrib.gis"] + INSTALLED_APPS

tests/test_integration.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import json
21
import os
32
import re
43
import unittest
54

65
import django
76
import html5lib
8-
from django.conf import settings
97
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
108
from django.core import signing
119
from django.core.cache import cache
@@ -18,7 +16,6 @@
1816
from debug_toolbar.forms import SignedDataForm
1917
from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar
2018
from debug_toolbar.panels import Panel
21-
from debug_toolbar.panels.sql.forms import SQLSelectForm
2219
from debug_toolbar.toolbar import DebugToolbar
2320

2421
from .base import BaseTestCase, IntegrationTestCase
@@ -310,28 +307,6 @@ def test_sql_explain_checks_show_toolbar(self):
310307
)
311308
self.assertEqual(response.status_code, 404)
312309

313-
@unittest.skipUnless(settings.USE_GIS, "Test only valid with gis support")
314-
def test_sql_explain_gis(self):
315-
from django.contrib.gis.geos import GEOSGeometry
316-
317-
from .models import Location
318-
319-
db_table = Location._meta.db_table
320-
321-
url = "/__debug__/sql_explain/"
322-
geom = GEOSGeometry("POLYGON((0 0, 0 1, 1 1, 0 0))")
323-
data = {
324-
"sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ {geom.hex} LIMIT 1',
325-
"raw_sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ %s LIMIT 1',
326-
"params": json.dumps([geom.hex]),
327-
"alias": "default",
328-
"duration": "0",
329-
}
330-
data["hash"] = SQLSelectForm().make_hash(data)
331-
332-
response = self.client.post(url, data=data)
333-
self.assertEqual(response.status_code, 200)
334-
335310
@unittest.skipUnless(
336311
connection.vendor == "postgresql", "Test valid only on PostgreSQL"
337312
)

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ setenv =
4949
DB_BACKEND = postgresql
5050
DB_PORT = {env:DB_PORT:5432}
5151

52+
[testenv:py{36,37,38,39,310}-dj{22,31,32,40,main}-postgis]
53+
setenv =
54+
{[testenv]setenv}
55+
DB_BACKEND = postgis
56+
DB_PORT = {env:DB_PORT:5432}
57+
5258
[testenv:py{36,37,38,39,310}-dj{22,31,32,40,main}-mysql]
5359
setenv =
5460
{[testenv]setenv}

0 commit comments

Comments
 (0)