From f695134841f3a885c2459f9cadd06eab58a288c8 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Tue, 14 Dec 2021 09:51:39 -0600 Subject: [PATCH 1/3] Avoid stripping additional characters from GIS SQL params. If the param lead or ended with characters identified in the strip calls, those characters would also be removed. Using split will retain all of the characters inbetween the given strings. When we drop support for < 3.9, we can switch to the removeprefix and removesuffix functions. Fixes #1543 --- debug_toolbar/panels/sql/tracking.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/panels/sql/tracking.py b/debug_toolbar/panels/sql/tracking.py index 7090ac613..b13db62c2 100644 --- a/debug_toolbar/panels/sql/tracking.py +++ b/debug_toolbar/panels/sql/tracking.py @@ -141,7 +141,9 @@ def _record(self, method, sql, params): def strip_GeomFromEWKB(param): if isinstance(param, str): - return param.lstrip("ST_GeomFromEWKB('\\x").rstrip("'::bytea)") + return param.split("ST_GeomFromEWKB('\\x", maxsplit=1)[ + 0 + ].rsplit("'::bytea)", maxsplit=1)[0] return param params = [strip_GeomFromEWKB(param) for param in params] From 50886dab0b39718c0fa0df61c223b723f67d1475 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Wed, 15 Dec 2021 11:34:56 -0600 Subject: [PATCH 2/3] Run postgis tests via tox. --- tox.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tox.ini b/tox.ini index 5d5e6b86e..3ffbe4021 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} From 68f8a1c15d906150e608a11fc4ab26e1a352bb87 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Wed, 15 Dec 2021 11:41:43 -0600 Subject: [PATCH 3/3] Run CI for postgis service. Include mention in the docs about how to configure the user locally to install PostgreSQL extensions. --- .github/workflows/test.yml | 67 ++++++++++++++++++++++++++++++++++++++ docs/contributing.rst | 5 +++ 2 files changed, 72 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 050d5b11d..a99e3474e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -142,6 +142,73 @@ jobs: with: name: Python ${{ matrix.python-version }} + postgis: + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] + + services: + postgres: + image: postgis/postgis:14-3.1 + env: + POSTGRES_DB: debug_toolbar + POSTGRES_USER: debug_toolbar + POSTGRES_PASSWORD: debug_toolbar + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Get pip cache dir + id: pip-cache + run: | + echo "::set-output name=dir::$(pip cache dir)" + + - name: Cache + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: + ${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/tox.ini') }} + restore-keys: | + ${{ matrix.python-version }}-v1- + + - name: Install enchant (only for docs) + run: | + sudo apt-get -qq update + sudo apt-get -y install enchant + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade tox tox-gh-actions + + - name: Test with tox + run: tox + env: + DB_BACKEND: postgis + DB_HOST: localhost + DB_PORT: 5432 + + - name: Upload coverage + uses: codecov/codecov-action@v1 + with: + name: Python ${{ matrix.python-version }} + sqlite: runs-on: ubuntu-latest strategy: diff --git a/docs/contributing.rst b/docs/contributing.rst index 1cbaf24d9..ec4e88845 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -89,6 +89,11 @@ databases):: psql> CREATE DATABASE debug_toolbar; psql> GRANT ALL PRIVILEGES ON DATABASE debug_toolbar to debug_toolbar; +If you're going to test the PostGIS integration locally the PostgreSQL user +will need to be a super user in order to create the extensions. + + psql> ALTER USER debug_toolbar WITH SUPERUSER; + For MySQL/MariaDB in a ``mysql`` shell:: mysql> CREATE DATABASE debug_toolbar;