Skip to content

Upgrade to psycopg3 - #1903

Draft
bmos wants to merge 18 commits into
move-coop:mainfrom
bmos:psycopg3
Draft

bmos wants to merge 18 commits into
move-coop:mainfrom
bmos:psycopg3

Conversation

@bmos

@bmos bmos commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

This PR picks up from #987

What is this change?

  • Update minimum version of SQLAlchemy to 2.0.51
  • Replace psycopg2-binary package with psycopg[binary] >= 3.3.4
  • Update all psycopg documentation links
  • Update all psycopg2 imports to equivalent psycopg imports
  • Add client_encoding arg to redshift connection

Considerations for discussion

  • Psycopg3 may be required to support python 3.15, as psycopg2-binary is a blocker in Test python 3.15 #1902
  • It's technically possible to support both for some period of time with a deprecation message, although it would be pretty messy. Would we want that?

How to test the changes (if needed)

  • Need to run live tests locally, as there is only 56% code coverage without live tests.
    I have not run the live tests. Postgres, Redshift, and Alchemy are the parts that are most in need of validation.

Breaking Changes

Breaking changes are changes to our public API which may require existing users to change their code. If there are no breaking changes, any existing parsons user should not need to do anything after updating their parsons version.

Does this PR introduce breaking changes?
  • label: Breaking change — This PR introduces one or more breaking changes.
  • label: Non-breaking change — This PR does not introduce one or more breaking changes.

Details (if needed)

Breaking changes to parameterization

A few parameterization patterns that worked with psycopg2 no longer work with psycopg3.
They are detailed on the migration guide, but these in particular should be highlighted:

  • You can no longer use IN %s with a tuple

    This would work with psycopg2 but will not work with psycopg3: conn.execute("SELECT * FROM foo WHERE id IN %s", parameters=[(10,20,30)])
    Instead, this format is advised: conn.execute("SELECT * FROM foo WHERE id = ANY(%s)", parameters=[[10,20,30]])

  • You can no longer use IS %s
    This would work with psycopg2 but will not work with psycopg3: conn.execute("SELECT * FROM foo WHERE field IS %s", [None])
    Instead, IS NOT DISTINCT FROM %s should be used conn.execute("SELECT * FROM foo WHERE field IS NOT DISTINCT FROM %s", [None])

  • Copy methods are refactored and consolidated in psycopg3, including breaking changes.
    See the migration guide for details.

@github-actions github-actions Bot added documentation Work type - improvements or additions to documentation testing Work type - writing or changing code tests for core Parsons features or Parsons connectors python Pull requests that update Python code labels Jul 17, 2026
@bmos
bmos requested a review from austinweisgrau July 17, 2026 22:56
@github-actions github-actions Bot added the breaking-change applied only to PRs, indicates when something has a breaking change to be flagged in release notes label Jul 17, 2026
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  parsons/databases
  alchemy.py 19-22
  parsons/databases/postgres
  postgres.py 55
  postgres_core.py 40, 49-53, 61-64
  parsons/databases/redshift
  redshift.py 135-151, 155-157
  parsons/utilities
  ssh_utilities.py
Project Total  

This report was generated by python-coverage-comment-action

@bmos bmos added the dependencies Pull requests that update a dependency file label Jul 17, 2026
@github-actions github-actions Bot removed the dependencies Pull requests that update a dependency file label Jul 17, 2026
@bmos bmos added the dependencies Pull requests that update a dependency file label Jul 17, 2026
@github-actions github-actions Bot removed the dependencies Pull requests that update a dependency file label Jul 17, 2026
@bmos bmos mentioned this pull request Jul 18, 2026
2 tasks
@shaunagm

Copy link
Copy Markdown
Collaborator

Psycopg2 was historically the single biggest source of installation issues for Parsons, so I am wary of touching it, especially with known breaking changes, before November. But we can queue this to merge afterwards (once it's ready of course).

@bmos

bmos commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

Absolutely. That's why I have kept this a draft for now.

I think we need pretty comprehensive testing from people who are already using these features. Especially because the supported queries appear to have changed pretty dramatically in version 3.

Comment thread parsons/databases/redshift/redshift.py Fixed
bmos and others added 3 commits August 24, 2026 19:04
Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 9.0.0 to 10.0.1.
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](astral-sh/setup-uv@c771a70...20cfd1b)

---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
  dependency-version: 10.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@github-actions github-actions Bot added the github_actions Pull requests that update GitHub Actions code label Sep 5, 2026
@github-actions github-actions Bot removed the github_actions Pull requests that update GitHub Actions code label Sep 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change applied only to PRs, indicates when something has a breaking change to be flagged in release notes documentation Work type - improvements or additions to documentation python Pull requests that update Python code testing Work type - writing or changing code tests for core Parsons features or Parsons connectors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants