From c965f31268cd058f9648c72cbd07eaa68739d810 Mon Sep 17 00:00:00 2001 From: Ethan Estrada Date: Mon, 22 Mar 2021 16:22:36 -0600 Subject: [PATCH] Only import psycopg2 where it is used Otherwise this module fails to import in environments where a different DB connector from psycopg2 is used. --- citext/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/citext/__init__.py b/citext/__init__.py index b9c4bd9..b3818f3 100644 --- a/citext/__init__.py +++ b/citext/__init__.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -import psycopg2.extensions import sqlalchemy import sqlalchemy.types as types from sqlalchemy.dialects.postgresql.base import ischema_names @@ -43,6 +42,8 @@ def process(value): def register_citext_array(engine): """Call once with an engine for citext values to be returned as strings instead of characters""" + import psycopg2.extensions + results = engine.execute(sqlalchemy.text("SELECT typarray FROM pg_type WHERE typname = 'citext'")) oids = tuple(row[0] for row in results) array_type = psycopg2.extensions.new_array_type(oids, 'citext[]', psycopg2.STRING)