Skip to content

Conversation

@j-bennet
Copy link
Contributor

@j-bennet j-bennet commented Mar 17, 2022

Description

Port pgcli to psycopg3. Work in progress.

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install), and ran black on my code.
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

@j-bennet j-bennet marked this pull request as draft March 17, 2022 16:54
@j-bennet
Copy link
Contributor Author

j-bennet commented Apr 3, 2022

@dvarrazzo Can you advise about register_json_typecasters here?

def register_json_typecasters(conn, loads_fn):

Do we still need this, and what would be the equivalent in psycopg if yes?

@dvarrazzo
Copy link
Collaborator

@dvarrazzo Can you advise about register_json_typecasters here?

@j-bennet I seem to remember that you only use that function to actually disable json loading, by calling register_json_typecasters(conn, lambda x: x), so that people would see the json data instead of the repr of the python objects. If that's the case, I suggest you to register the text loader for it as you do in register_typecasters() with other types:

def register_typecasters(connection):
    ...
    connection.adapters.register_loader("json", psycopg.types.string.TextLoader)
    connection.adapters.register_loader("jsonb", psycopg.types.string.TextLoader)

and to drop register_json_typecaster() altogether.

A function similar to the psycopg2 one is available as psycopg.types.json.set_json_loads (see Json adaptation for details), but I don't think it covers your use case. That function is meant to customise loads(); you need to disable it.

The exception checking in the old code is not necessary. It was necessary in the past to look for the oid of json/jsonb types, when they were still Postgres extensions. Now that they are in core, their oids are fixed and well known, so psycopg doesn't need to run queries which might fail. Even if you run pgcli with an old Postgres version, the function calls in register_typecaster() wouldn't fail.

@j-bennet j-bennet force-pushed the j-bennet/psycopg3 branch from 0e32045 to 36b890a Compare May 13, 2022 01:31
@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 13, 2022

This pull request introduces 2 alerts and fixes 3 when merging 36b890a into 372da81 - view on LGTM.com

new alerts:

  • 2 for Unused import

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 13, 2022

This pull request introduces 2 alerts and fixes 3 when merging 3217134 into 372da81 - view on LGTM.com

new alerts:

  • 2 for Unused import

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@codecov-commenter
Copy link

codecov-commenter commented May 13, 2022

Codecov Report

Merging #1324 (b581b75) into main (6884c29) will decrease coverage by 5.02%.
The diff coverage is 34.42%.

@@            Coverage Diff             @@
##             main    #1324      +/-   ##
==========================================
- Coverage   84.15%   79.13%   -5.03%     
==========================================
  Files          21       23       +2     
  Lines        2720     2880     +160     
==========================================
- Hits         2289     2279      -10     
- Misses        431      601     +170     
Impacted Files Coverage Δ
pgcli/pgtoolbar.py 31.57% <0.00%> (+0.15%) ⬆️
pgcli/pyev.py 15.38% <15.38%> (ø)
pgcli/explain_output_formatter.py 46.15% <46.15%> (ø)
pgcli/key_bindings.py 52.94% <50.00%> (-0.19%) ⬇️
pgcli/pgexecute.py 82.52% <83.92%> (+2.15%) ⬆️
pgcli/main.py 78.15% <89.47%> (-0.39%) ⬇️
pgcli/__init__.py 100.00% <100.00%> (ø)
pgcli/packages/prioritization.py 96.96% <0.00%> (-3.04%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 372da81...b581b75. Read the comment docs.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 13, 2022

This pull request introduces 2 alerts and fixes 3 when merging 51459a5 into 372da81 - view on LGTM.com

new alerts:

  • 2 for Unused import

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 13, 2022

This pull request introduces 2 alerts and fixes 3 when merging a6188c4 into 372da81 - view on LGTM.com

new alerts:

  • 2 for Unused import

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 13, 2022

This pull request introduces 2 alerts and fixes 3 when merging e2584f3 into 372da81 - view on LGTM.com

new alerts:

  • 2 for Unused import

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@j-bennet j-bennet force-pushed the j-bennet/psycopg3 branch 2 times, most recently from c57fe5d to ad095b7 Compare May 28, 2022 00:09
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@j-bennet j-bennet force-pushed the j-bennet/psycopg3 branch from 943aa0c to edd3b49 Compare May 28, 2022 21:00
@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 28, 2022

This pull request fixes 3 alerts when merging edd3b49 into 372da81 - view on LGTM.com

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@dbcli dbcli deleted a comment from lgtm-com bot May 28, 2022
@j-bennet j-bennet marked this pull request as ready for review May 28, 2022 21:29
@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 28, 2022

This pull request fixes 3 alerts when merging b581b75 into 372da81 - view on LGTM.com

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 3, 2022

This pull request fixes 3 alerts when merging 840c6aa into 372da81 - view on LGTM.com

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 3, 2022

This pull request fixes 3 alerts when merging 2c82435 into 372da81 - view on LGTM.com

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Module is imported more than once

@j-bennet j-bennet merged commit 1807175 into main Jun 6, 2022
@j-bennet j-bennet deleted the j-bennet/psycopg3 branch June 6, 2022 18:20
@j-bennet j-bennet mentioned this pull request Jan 2, 2023
4 tasks
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.

5 participants