From 97e4d70b88b51593740ff85f7b803b4620747c26 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Wed, 15 Dec 2021 12:04:17 -0600 Subject: [PATCH] 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 --- .github/workflows/test.yml | 5 +++-- debug_toolbar/panels/sql/tracking.py | 8 -------- docs/changes.rst | 3 +++ tests/settings.py | 2 +- tests/test_integration.py | 25 ------------------------- tox.ini | 6 ++++++ 6 files changed, 13 insertions(+), 36 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 050d5b11d..2ef517555 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -82,10 +82,11 @@ jobs: max-parallel: 5 matrix: python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] + database: ['postgres', 'postgis'] services: postgres: - image: postgres + image: postgis/postgis:14-3.1 env: POSTGRES_DB: debug_toolbar POSTGRES_USER: debug_toolbar @@ -133,7 +134,7 @@ jobs: - name: Test with tox run: tox env: - DB_BACKEND: postgresql + DB_BACKEND: ${{ matrix.database }} DB_HOST: localhost DB_PORT: 5432 diff --git a/debug_toolbar/panels/sql/tracking.py b/debug_toolbar/panels/sql/tracking.py index 7090ac613..2ed691344 100644 --- a/debug_toolbar/panels/sql/tracking.py +++ b/debug_toolbar/panels/sql/tracking.py @@ -137,14 +137,6 @@ def _decode(self, param): def _record(self, method, sql, params): start_time = time() try: - if isinstance(params, list): - - def strip_GeomFromEWKB(param): - if isinstance(param, str): - return param.lstrip("ST_GeomFromEWKB('\\x").rstrip("'::bytea)") - return param - - params = [strip_GeomFromEWKB(param) for param in params] return method(sql, params) finally: stop_time = time() diff --git a/docs/changes.rst b/docs/changes.rst index 5c623e79f..8ae900586 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,9 @@ Change log Next version ------------ +* Revert PR 1426 - Fixes issue with SQL params having leading and trailing + characters stripped away. + 3.2.3 (2021-12-12) ------------------ diff --git a/tests/settings.py b/tests/settings.py index 63456a2f6..c09506087 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -27,7 +27,7 @@ "tests", ] -USE_GIS = os.getenv("DB_BACKEND") in ("postgis",) +USE_GIS = os.getenv("DB_BACKEND") == "postgis" if USE_GIS: INSTALLED_APPS = ["django.contrib.gis"] + INSTALLED_APPS diff --git a/tests/test_integration.py b/tests/test_integration.py index 006ab93ee..ff6d32d9f 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,11 +1,9 @@ -import json import os import re import unittest import django import html5lib -from django.conf import settings from django.contrib.staticfiles.testing import StaticLiveServerTestCase from django.core import signing from django.core.cache import cache @@ -18,7 +16,6 @@ from debug_toolbar.forms import SignedDataForm from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar from debug_toolbar.panels import Panel -from debug_toolbar.panels.sql.forms import SQLSelectForm from debug_toolbar.toolbar import DebugToolbar from .base import BaseTestCase, IntegrationTestCase @@ -310,28 +307,6 @@ def test_sql_explain_checks_show_toolbar(self): ) self.assertEqual(response.status_code, 404) - @unittest.skipUnless(settings.USE_GIS, "Test only valid with gis support") - def test_sql_explain_gis(self): - from django.contrib.gis.geos import GEOSGeometry - - from .models import Location - - db_table = Location._meta.db_table - - url = "/__debug__/sql_explain/" - geom = GEOSGeometry("POLYGON((0 0, 0 1, 1 1, 0 0))") - data = { - "sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ {geom.hex} LIMIT 1', - "raw_sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ %s LIMIT 1', - "params": json.dumps([geom.hex]), - "alias": "default", - "duration": "0", - } - data["hash"] = SQLSelectForm().make_hash(data) - - response = self.client.post(url, data=data) - self.assertEqual(response.status_code, 200) - @unittest.skipUnless( connection.vendor == "postgresql", "Test valid only on PostgreSQL" ) diff --git a/tox.ini b/tox.ini index dcbd607ff..13bf73037 100644 --- a/tox.ini +++ b/tox.ini @@ -49,6 +49,12 @@ setenv = DB_BACKEND = postgresql DB_PORT = {env:DB_PORT:5432} +[testenv:py{36,37,38,39,310}-dj{22,31,32,40,main}-postgis] +setenv = + {[testenv]setenv} + DB_BACKEND = postgis + DB_PORT = {env:DB_PORT:5432} + [testenv:py{36,37,38,39,310}-dj{22,31,32,40,main}-mysql] setenv = {[testenv]setenv}