Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to psycopg 3 #2740

Closed
phillxnet opened this issue Nov 11, 2023 · 4 comments
Closed

update to psycopg 3 #2740

phillxnet opened this issue Nov 11, 2023 · 4 comments
Assignees
Milestone

Comments

@phillxnet
Copy link
Member

phillxnet commented Nov 11, 2023

As part of our ongoing modernisation, and post our move to Django 4.2, we can adopt the async capable psycopg 3.

This is a requirement for: "Django Server Sent Events to provide live data requirements" #2739

Project Docs: https://www.psycopg.org/psycopg3/docs/

Fun fact: there is no psycopg3 package, only psycopg!

PyPi: https://pypi.org/project/psycopg/
Latest is 3.1.13 Released: Nov 17, 2023

https://www.psycopg.org/psycopg3/docs/basic/install.html#supported-systems

Python: from version 3.8 to 3.12

PostgreSQL: from version 10 to 16

Pure Python installation

https://www.psycopg.org/psycopg3/docs/basic/install.html#pure-python-installation

In order to use the pure Python installation you will need the libpq installed in the system: for instance on Debian system you will probably need:

sudo apt install libpq5

The libpq is the client library used by psql, the PostgreSQL command line client, to connect to the database. On most systems, installing psql will install the libpq too as a dependency.

Differences from psycopg2

https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html#differences-from-psycopg2

@phillxnet phillxnet added this to the Django 4.2 milestone Nov 11, 2023
@phillxnet phillxnet self-assigned this Nov 21, 2023
@phillxnet
Copy link
Member Author

Our existing use of psycopg2 is now one of our older dependencies. Given we are now on the indicated Django 4.2 we have the following constraint re psycopg 3:

https://django.readthedocs.io/en/latest/releases/4.2.html#psycopg-3-support

Psycopg 3 support
Django now supports psycopg version 3.1.8 or higher. To update your code, install the psycopg library, you don’t need to change the ENGINE as django.db.backends.postgresql supports both libraries.

Support for psycopg2 is likely to be deprecated and removed at some point in the future.

Be aware that psycopg 3 introduces some breaking changes over psycopg2. As a consequence, you may need to make some changes to account for differences from psycopg2.

@phillxnet
Copy link
Member Author

Adjusting our pinning to a 3 major version only: "~3" we have the following:

lbuildvm:/opt/rockstor # poetry update
Updating dependencies
Resolving dependencies... (7.9s)

Writing lock file

Package operations: 1 install, 1 update, 1 removal

  • Removing psycopg2 (2.8.6)
  • Updating certifi (2023.7.22 -> 2023.11.17)
  • Installing psycopg (3.1.13)

So we have one incidental update of:

  • Updating certifi (2023.7.22 -> 2023.11.17)

PyPi.org: https://pypi.org/project/certifi/
This is a single release version update:

Our new psycopg (3) has the following, non unique dependencies:

psycopg 3.1.13 PostgreSQL database adapter for Python
├── typing-extensions >=4.1
└── tzdata *

@phillxnet
Copy link
Member Author

Tests

lbuildvm:/opt/rockstor # poetry run python -Wa .venv/bin/django-admin test
Found 0 test(s).
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
lbuildvm:/opt/rockstor/src/rockstor # poetry run django-admin test -v 2
...
----------------------------------------------------------------------
Ran 278 tests in 40.166s

OK
Destroying test database for alias 'default' ('test_storageadmin')...
Destroying test database for alias 'smart_manager' ('test_smartdb')...

phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Nov 21, 2023
Update to latest psycopg 3.1.13 from psycopg2 2.8.6.
## Includes
- Update settings.py database ENGINE configs:
from: django.db.backends.postgresql_psycopg2
to:  django.db.backends.postgresql
- Incidental update of certifi (2023.7.22 -> 2023.11.17)
phillxnet added a commit that referenced this issue Nov 22, 2023
@phillxnet
Copy link
Member Author

Closing as:
Fixed by #2753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant