Skip to content

Support psycopg3 #208

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

Merged
merged 6 commits into from
Apr 6, 2023
Merged

Support psycopg3 #208

merged 6 commits into from
Apr 6, 2023

Conversation

snuderl
Copy link
Contributor

@snuderl snuderl commented Apr 5, 2023

Very minor changes needed to support this.

I am not sure what the best way to add tests for this would be, as ideally test would ran against both psycopg2 and psycopg3.

Edit:
Set up the tests.

P.S.
Really sweet testing setup.

@Photonios
Copy link
Member

I am not sure what the best way to add tests for this would be, as ideally test would ran against both psycopg2 and psycopg3.

This could be fixed by adding a new dimension to the Tox configuration file which already runs the tests against multiple Django and Python versions. See: https://github.com/SectorLabs/django-postgres-extra/blob/master/tox.ini

Copy link
Member

@Photonios Photonios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


# create a mapping between column names and column value
return [
{
column.name: row[column_index]
for column_index, column in enumerate(cursor.description)
for column_index, column in enumerate(description)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change. How is aliasing it on line 190 changing how this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the with cursor now cleans up the data on the cursor on exit. So cusror.description ends up being None. So we just need to read it before the with block exits

@snuderl snuderl force-pushed the psycopg3 branch 4 times, most recently from f829c93 to 118bf09 Compare April 6, 2023 06:49
@snuderl snuderl requested a review from Photonios April 6, 2023 06:56
damjankuznar
damjankuznar previously approved these changes Apr 6, 2023
Copy link

@damjankuznar damjankuznar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -42,6 +42,12 @@ commands:
environment:
DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra'

- run:
name: Run tests psycopg3
command: tox -e 'py<< parameters.pyversion >>-dj{<< parameters.djversions >>}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this install psycopg3? I don't see any references in tox.ini to psycopg3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry, this was me trying to figure tox/circle out

Right now the djversion=42 uses psycopg3 (though It means that it does not test psycopg2)

@@ -11,6 +11,7 @@ deps =
dj32: Django~=3.2.0
dj40: Django~=4.0.0
dj41: Django~=4.1.0
dj42: .[psycopg3]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the tests don't run against psycopg2 anymore. I will patch this up after merging this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#209

I just added this. Tests run against psycopg 2.8, 2.9 and 3.0 now with all supported Django versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Photonios Photonios merged commit b428fda into SectorLabs:master Apr 6, 2023
@Photonios
Copy link
Member

@snuderl You can try it out in v2.0.9rc2

@snuderl
Copy link
Contributor Author

snuderl commented Apr 7, 2023

@snuderl You can try it out in v2.0.9rc2

Yup. Works with our codebase!

@adamantike
Copy link

I was also experiencing this issue, and bumping to one of the current RC releases fixed it. Looking for a new release to unpin our dependency from RC! 🙂

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

Successfully merging this pull request may close these issues.

4 participants