Skip to content
Snippets Groups Projects

migrating to psycopg3

Merged Pierre-Yves David requested to merge marmoute/swh-core:psycopg3 into master

:warning: Need to be landed in concert with other update of swh modul. Benchmark report visible at swh-storage!1160 (merged)

And these is a few remaining check to do :

  • do have a "dropping password from connection info" issue.
Edited by Pierre-Yves David

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
124 126 @staticmethod
125 def adapt_conn(conn: psycopg2.extensions.connection):
126 """Makes psycopg2 use 'bytes' to decode bytea instead of
127 def adapt_conn(conn: psycopg.Connection[Any]):
128 """Makes psycopg use 'bytes' to decode bytea instead of
127 129 'memoryview', for this connection."""
128 t_bytes = psycopg2.extensions.new_type((17,), "bytea", typecast_bytea)
129 psycopg2.extensions.register_type(t_bytes, conn)
130 # XXX-psycophg3: deal with this
131 # t_bytes = psycopg.extensions.new_type((17,), "bytea", typecast_bytea)
132 # psycopg.extensions.register_type(t_bytes, conn)
130 133
131 t_bytes_array = psycopg2.extensions.new_array_type((1001,), "bytea[]", t_bytes)
132 psycopg2.extensions.register_type(t_bytes_array, conn)
134 # t_bytes_array = psycopg.extensions.new_array_type((1001,), "bytea[]", t_bytes)
135 # psycopg.extensions.register_type(t_bytes_array, conn)
  • 62 62 ls: list, of, strings
    63 63 li: 1, 2, 3, 4
    64 64 """
    65 conffile.open("w").write(conf_contents)
    65 with open(conffile, "w") as f:
    66 f.write(conf_contents)
  • 28 28 cursor.execute("SHOW %s" % option)
    29 29 old_value = cursor.fetchall()[0][0]
    30 30 if old_value != value:
    31 cursor.execute("SET LOCAL %s TO %%s" % option, (value,))
    31 # XXX-psycopg3: use SQL oriented formatting instead
    32 cursor.execute(
    33 "SELECT set_config(%s::text, %s::text, true)", (option, value)
  • 623 573
    624 574 def parse_dsn_or_dbname(dsn_or_dbname: str) -> Dict[str, str]:
    625 """Parse a psycopg2 dsn, falling back to supporting plain database names as well"""
    575 """Parse a psycopg dsn, falling back to supporting plain database names as well"""
    626 576 try:
    627 return _parse_dsn(dsn_or_dbname)
    628 except psycopg2.ProgrammingError:
    629 # psycopg2 failed to parse the DSN; it's probably a database name,
    577 d = conninfo_to_dict(dsn_or_dbname)
    578 except psycopg.ProgrammingError:
    579 # psycopg failed to parse the DSN; it's probably a database name,
    630 580 # handle it as such
    631 return _parse_dsn(f"dbname={dsn_or_dbname}")
    581 d = conninfo_to_dict(f"dbname={dsn_or_dbname}")
    582 # typing note: we don't pass **kwargs to conninfo_to_dict, so we don't get
    583 # "int/None" as value and can safely cast to `Dict[str, str]`
  • 1 1 hypothesis >= 3.11.0
    2 psycopg_pool
  • Pierre-Yves David changed the description

    changed the description

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading