Migrate psycopg2 -> psycopg 3 - #903
Merged
Merged
Conversation
anderdc
requested changes
May 5, 2026
anderdc
left a comment
Collaborator
There was a problem hiding this comment.
- Fix conflicts.
- Pin
psycopg[binary]to a specific version (e.g.==3.3.3) — rest ofpyproject.tomluses exact pins.
anderdc
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #902
Summary
psycopg2-binarywithpsycopg[binary]>=3.2execute_values(unsupported in v3) and switch each bulk upsert tocursor.executemany, with the SQL templates expanded fromVALUES %sto explicitVALUES (%s, %s, ...)row tuplesdb_connection.pipeline()to batch queries into one round-trip while preserving the existing transaction boundary. From documentation:connection.prepare_threshold = 0so our queries are auto-prepared, instead of old behavior, when it was undefined. From documentation:RepositoryorDatabaseStoragedbnamearg instead ofdatabase, like in canonical usage example: https://www.psycopg.org/psycopg3/docs/basic/usage.html#main-objects-in-psycopg-3; Keyword list: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDSTest plan
I haven't added new tests as currently there are no any tests which cover the real database connection, either any migrations to spin-up everything locally. I did some synthetic manual testing and everything seems good.
I can try to implement necessary code here to test it against a real connection and do real tests if you want.