Django 4.2, PyPy and Postgres

100 views
Skip to first unread message

Pete Doherty

unread,
Dec 11, 2023, 3:19:11 PM12/11/23
to Django users
I'm wondering if anyone is using Django 4.2, PyPy 3.10 and Postgres 15?

I tried using psycopg2cffi==2.9.0 and it works up until a point but eventually fails with a series of errors relating to imports.

After adding the compatibility layer to the top of my settings.py script using:

> from psycopg2cffi import compat, errorcodes
> compat.register()


The first error I see is:

> ImportError: cannot import name 'errors' from 'psycopg2cffi' (/home/appuser/.local/lib/pypy3.10/site-packages/psycopg2cffi/__init__.py)

I see the errors module in the psycopg2cffi repo and seem to be able to import it like so:

> import psycopg2cffi
> from psycopg2cffi import compat, errorcodes
psycopg2cffi.errors = errorcodes

I then see an error stating:

> ImportError: cannot import name 'sql' from 'psycopg2cffi' (/home/appuser/.local/lib/pypy3.10/site-packages/psycopg2cffi/__init__.py)

While I see the sql.py module in the repo, it does not seem to be included in the built psycopg2cffi package. Trying to patch it in results in:

> from psycopg2cffi import sql
> psycopg2cffi.sql = sql

> ImportError: cannot import name 'sql' from 'psycopg2cffi' (/home/appuser/.local/lib/pypy3.10/site-packages/psycopg2cffi/__init__.py)

I tried copying sql.py into my locally installed package and that resulted yet another error:

> ImportError: cannot import name 'PY3' from 'psycopg2cffi.compat' (/home/appuser/.local/lib/pypy3.10/site-packages/psycopg2cffi/compat.py)

So, before I go any further down this path, I wanted to see if anyone is using this setup, knows that it will definitely not work or has any suggestions about alternatives.

Thanks!

Jason

unread,
Dec 11, 2023, 9:28:06 PM12/11/23
to Django users
the last release of psycopg2cffi was January 2021

pypy support for 3.10 came out Dec 2022

Is there a reason you're on psycopg2cffi?  have you tried with regular psycopg2?

Pete Doherty

unread,
Dec 12, 2023, 10:51:29 AM12/12/23
to Django users
I did try using psycopg2-binary and the app wouldn't start. I'll have to revisit to find what that exact error was. That's a good suggestion, though, as I did not try with the Python (i.e. non-binary) package.

Anyways, the consensus after a quick web search seemed to be to use psycopg2cffi when using PyPy. I'm open to any driver that'll work, though. This is just an experiment.

Pete Doherty

unread,
Dec 12, 2023, 12:58:11 PM12/12/23
to Django users
Interestingly, I can confirm that using Psycopg 3 does seem to work. I only got it working a few minutes ago, so it has not been thoroughly tested but my test suite passes, which is very encouraging.

Thanks for the nudge, Jason.

Jason

unread,
Dec 12, 2023, 8:46:15 PM12/12/23
to Django users
sweet, glad this worked out, and hope the initial promise continues to hold true.
Reply all
Reply to author
Forward
0 new messages