diff --git a/citext/__init__.py b/citext/__init__.py index b9c4bd9..466ea28 100644 --- a/citext/__init__.py +++ b/citext/__init__.py @@ -12,6 +12,7 @@ class CIText(types.Concatenable, types.UserDefinedType): # This is copied from the `literal_processor` of sqlalchemy's own `String` # type. + cache_ok = True def literal_processor(self, dialect): def process(value): value = value.replace("'", "''") @@ -43,7 +44,10 @@ def process(value): def register_citext_array(engine): """Call once with an engine for citext values to be returned as strings instead of characters""" - results = engine.execute(sqlalchemy.text("SELECT typarray FROM pg_type WHERE typname = 'citext'")) + with engine.connect() as connection: + # Using engine.execute() is deprecated in SQLAlchemy >=1.4,<2, removed in >=2 + # Using engine.connect().execute() is compatible with *all* SQLAlchemy >= 1.1 (and probably further back) + results = connection.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) psycopg2.extensions.register_type(array_type, None)