Error/problem with psycopg3 and server-side cursors


I recently upgraded to django 4.2.4 and decided to give psycopg3 a try. I’ve been using psycopg2 for years without any problems. But with psycopg3, I get an exception for many of my create/edit form views. The exception thrown is:

NotSupportedError at [snip]/units/new/

server-side cursors not supported in pipeline mode

If I enable DISABLE_SERVER_SIDE_CURSORS in the settings, it seems to work fine. If I use psycopg2 instead, it also works. It’s worth noting that the database uses default values for ATOMIC_REQUESTS and AUTOCOMMIT.

Is this expected? Should I just enable DISABLE_SERVER_SIDE_CURSORS, and if yes, is there any downside? Or should I just stick to psycopg2 (although django docs say it’ll be deprecated, so it’s a concern)?

UPDATE: The error seems to be thrown when rendering a related field in the template, while iterating over the choice queryset. There might be other scenarios, but at the moment, that’s the only one I can see.

It appears that there might be a setting you need to make for server-side cursors?
See Server-side parameters binding

The docs also reference this: Differences from psycopg2 - psycopg 3.2.0.dev1 documentation

Thanks for the feedback. Changing server_side_binding value didn’t have any effect.

As it turns out, I believe the problem is more fundamental. I installed psycopg3 with pip install "psycopg[binary]" on my standard Ubuntu 20.04 server (with libpq5 package installed). And I think the binary version of psycopg3 is not ABI compatible with that system.

With debug enabled in django and looking at the backtrace, the last entry would look like this:

What caught my attention is the invalid/unexpected PipelineStatus value. This could typically happen if the compiled code is retrieving the status from an incorrect address/offset. So I figured the precompiled binary package might be at fault here. I tried both pure-python (pip install psycopg) and local-install (pip install "psycopg[c]"), and they both work fine.

1 Like