mahmoudimus / sqlalchemy-citext

CITEXT type for SQLAlchemy
Other
29 stars 14 forks source link

Support psycopg3 #26

Open di opened 2 years ago

di commented 2 years ago

This library currently expects psycopg2 to be co-installed, but psycopg3 has since been released, which is currently incompatible:

Dockerfile:

from python

RUN python -m pip install -U pip psycopg sqlalchemy-citext

RUN python -c "import citext"

Result:

$ docker build .
[+] Building 8.3s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                            0.0s
 => => transferring dockerfile: 35B                                             0.0s
 => [internal] load .dockerignore                                               0.0s
 => => transferring context: 2B                                                 0.0s
 => [internal] load metadata for docker.io/library/python:latest                0.0s
 => CACHED [1/3] FROM docker.io/library/python                                  0.0s
 => [2/3] RUN python -m pip install -U pip psycopg sqlalchemy-citext            7.8s
 => ERROR [3/3] RUN python -c "import citext"                                   0.3s
------
 > [3/3] RUN python -c "import citext":
#6 0.317 Traceback (most recent call last):
#6 0.317   File "<string>", line 1, in <module>
#6 0.318   File "/usr/local/lib/python3.9/site-packages/citext/__init__.py", line 3, in <module>
#6 0.319     import psycopg2.extensions
#6 0.320 ModuleNotFoundError: No module named 'psycopg2'
------
executor failed running [/bin/sh -c python -c "import citext"]: exit code: 1
Patryk-Foryszewski commented 3 weeks ago

@di I've run into the same issue and I've been struggling for a while to solve it but I can't. How to deal with this?

gordthompson commented 3 weeks ago

Native support for CITEXT was added in SQLAlchemy 2.0.7 and bug-fixed in 2.0.19.

https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#sqlalchemy.dialects.postgresql.CITEXT

Patryk-Foryszewski commented 3 weeks ago

@gordthompson Thank you, I supposed it to be imported from sqlalchemy as Integer, String, UUID etc. Turns out to import CITEXT:

from sqlalchemy.dialects.postgresql.types import CITEXT