Skip to content

added support and test cases for psycopg3 #1737

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

Closed
wants to merge 16 commits into from
Closed

added support and test cases for psycopg3 #1737

wants to merge 16 commits into from

Conversation

nofalx
Copy link
Contributor

@nofalx nofalx commented Feb 6, 2023

Description

Add support for psycopg3 while still keeping support for psycopg2

Fixes #1736

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.
  • Fix test tests.panels.test_sql.SQLPanelMultiDBTestCase.test_transaction_status

Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

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

Thanks for starting this! Most of the code looks good but I haven't given it a very close reading yet.

@pauloxnet
Copy link
Member

there's typos in tile and description: it's 'psycopg' and not 'psycorg'

@nofalx nofalx changed the title added support and test cases for pyscorg3 added support and test cases for psycopg3 Feb 6, 2023
@@ -205,7 +214,7 @@ def _record(self, method, sql, params):
# case where Django can start a transaction before the first query
# executes, so in that case logger.current_transaction_id() will
# generate a new transaction ID since one does not already exist.
final_conn_status = conn.status
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like the old logic was based on connection status,
https://www.psycopg.org/docs/extensions.html#connection-status-constants

however according to the new api in psycopg3 connection.info.status we only have 2 states
https://www.psycopg.org/psycopg3/docs/api/pq.html#psycopg.pq.ConnStatus

Since STATUS_IN_TRANSACTION is never in any of the options of connection.info.status the test tests.panels.test_sql.SQLPanelMultiDBTestCase.test_transaction_status will always fail. How should we based the logic for the new states of psycopg3? should we rely on conn.info.transaction_status instead of connection.info.status

nofalx and others added 3 commits February 6, 2023 21:00
Co-authored-by: Matthias Kestenholz <mk@feinheit.ch>
tox.ini Outdated
py{310}-dj{40}-{sqlite}
py{310,311}-dj{41,42,main}-{sqlite,postgresql,postgis,mysql}
py{310,311}-dj{40,41}-{sqlite,legacy_postgresql,postgis,mysql}
Copy link
Member

Choose a reason for hiding this comment

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

Now you're adding back many Django 4.0 test runs, those have been removed on purpose in #1719. That's not better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad, should be good this time

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 github actions still tries to run python3.8 with django 4.2a
https://github.com/jazzband/django-debug-toolbar/actions/runs/4113633936/jobs/7102476809#step:9:26

can you help adjust the test to prevent that?

Comment on lines 240 to 246
if is_psycopg3:
list(
PostgresJSON.objects.raw(
"SELECT * FROM tests_postgresjson WHERE field ->> 'key' = ANY(%s)",
[["a", "b'"]],
)
)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, we had a misunderstanding. This block does not fulfill the purpose of the test. If psycopg3 doesn't support tuples as a parameter, this test should fail expectedly. However, it doesn't look like there's a expectedFailureIf decorator, so maybe we update the skipUnless to include confirming it's psycopg2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was not sure how to check if we have psycopg3

so i relied on the method used with django to detect psycopg version
https://github.com/django/django/blob/main/django/db/backends/postgresql/base.py#L24

and combined it with self.skipTest

let me know if there is a better way to skip the test

Copy link
Member

Choose a reason for hiding this comment

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

@nofalx can you enable maintainers to edit the PR? I'd like to push a change. It should be on the right side near the notifications button. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

@nofalx nofalx requested a review from tim-schilling February 8, 2023 15:20
@nofalx
Copy link
Contributor Author

nofalx commented Feb 9, 2023

closed in favor for #1739 as the option "Allow edits by maintainers
" is not allowed here

@nofalx nofalx closed this Feb 9, 2023
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.

Add Support for psycopg3
4 participants