diff --git a/mapit/models.py b/mapit/models.py index d51d9164..08de91bb 100644 --- a/mapit/models.py +++ b/mapit/models.py @@ -18,9 +18,8 @@ def materialized(): - version = connection.cursor().connection.server_version materialized = '' - if version >= 120000: + if connection.pg_version >= 120000: materialized = 'MATERIALIZED' return materialized @@ -191,8 +190,8 @@ def intersect(self, query_type, area, types, generation): params = [area.id, area.id, generation.id, generation.id] if types: - params.append(tuple(types)) - query_area_type = ' AND mapit_area.type_id IN (SELECT id FROM mapit_type WHERE code IN %s) ' + params.append(list(types)) + query_area_type = ' AND mapit_area.type_id IN (SELECT id FROM mapit_type WHERE code = ANY(%s)) ' else: query_area_type = '' @@ -452,7 +451,7 @@ def filter_by_area(self, area, limit=''): WHERE area_id = %s''' query = ''' WITH target AS %s ( %s ) -SELECT "mapit_postcode"."id", "mapit_postcode"."postcode", "mapit_postcode"."location"::bytea +SELECT "mapit_postcode"."id", "mapit_postcode"."postcode", "mapit_postcode"."location" FROM mapit_postcode, target WHERE ST_CoveredBy(location, target.division) %s diff --git a/mapit/views/areas.py b/mapit/views/areas.py index 1791f41e..2cc6073a 100644 --- a/mapit/views/areas.py +++ b/mapit/views/areas.py @@ -1,5 +1,5 @@ import re -from psycopg2 import InternalError +from django.db import InternalError from django.db.utils import DatabaseError from django.utils.translation import gettext as _ diff --git a/mapit_gb/management/commands/mapit_UK_add_ons_to_gss.py b/mapit_gb/management/commands/mapit_UK_add_ons_to_gss.py index cee7ccb1..1d781d53 100644 --- a/mapit_gb/management/commands/mapit_UK_add_ons_to_gss.py +++ b/mapit_gb/management/commands/mapit_UK_add_ons_to_gss.py @@ -7,7 +7,7 @@ import sys from django.core.management.base import BaseCommand from mapit.models import Area, CodeType -from psycopg2 import IntegrityError +from django.db import IntegrityError python_version = sys.version_info[0] diff --git a/mapit_gb/management/commands/mapit_UK_update_ons_ids.py b/mapit_gb/management/commands/mapit_UK_update_ons_ids.py index cb2e420b..e758db9e 100644 --- a/mapit_gb/management/commands/mapit_UK_update_ons_ids.py +++ b/mapit_gb/management/commands/mapit_UK_update_ons_ids.py @@ -3,7 +3,7 @@ import csv from django.core.management.base import BaseCommand from mapit.models import Area, Generation, CodeType -from psycopg2 import IntegrityError +from django.db import IntegrityError class Command(BaseCommand): diff --git a/mapit_gb/management/commands/mapit_UK_update_ons_ids2.py b/mapit_gb/management/commands/mapit_UK_update_ons_ids2.py index afba95e2..81e69b47 100644 --- a/mapit_gb/management/commands/mapit_UK_update_ons_ids2.py +++ b/mapit_gb/management/commands/mapit_UK_update_ons_ids2.py @@ -4,7 +4,7 @@ import csv from django.core.management.base import BaseCommand from mapit.models import Area, Generation, CodeType -from psycopg2 import IntegrityError +from django.db import IntegrityError class Command(BaseCommand): diff --git a/setup.py b/setup.py index a31ad4e2..f99bdc11 100644 --- a/setup.py +++ b/setup.py @@ -53,11 +53,13 @@ def read_file(filename): install_requires=[ 'Django >= 4.2, <6.0', 'libsass >= 0.13.3', - 'psycopg2', 'PyYAML', 'Shapely', 'uk-postcode-utils', ], + extras_require={ + 'psycopg': ['psycopg'], + }, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', diff --git a/tox.ini b/tox.ini index 52cf6e5d..5fe660d6 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,8 @@ envlist = flake8, py310-{4.2,5.2} commands = flake8: flake8 mapit mapit_gb mapit_it mapit_no mapit_se mapit_za project py310: python -W all -W ignore::PendingDeprecationWarning -m coverage run --source mapit manage.py test mapit mapit_gb +extras = + py310: psycopg deps = py310: coverage flake8: flake8