Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Bump types-psycopg2 from 2.9.21.11 to 2.9.21.13 #16343

Closed
wants to merge 4 commits into from

Conversation

dependabot[bot]
Copy link
Contributor

@dependabot dependabot bot commented on behalf of github Sep 18, 2023

Bumps types-psycopg2 from 2.9.21.11 to 2.9.21.13.

Commits

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

Bumps [types-psycopg2](https://github.com/python/typeshed) from 2.9.21.11 to 2.9.21.13.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-psycopg2
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
@dependabot dependabot bot requested a review from a team as a code owner September 18, 2023 04:42
@dependabot dependabot bot added dependencies Pull requests from dependabot that update a dependency file python Pull requests that update Python code labels Sep 18, 2023
@DMRobertson
Copy link
Contributor

DMRobertson commented Sep 18, 2023

 synapse/storage/engines/postgres.py:35: error: Type argument "connection" of "BaseDatabaseEngine" must be a subtype of "Connection"  [type-var]
synapse/storage/engines/postgres.py:35: error: Type argument "cursor" of "BaseDatabaseEngine" must be a subtype of "Cursor"  [type-var]
synapse/storage/engines/postgres.py:105: error: Argument 1 to "get_db_locale" of "PostgresEngine" has incompatible type "cursor"; expected "Cursor"  [arg-type]
synapse/storage/engines/postgres.py:105: note: Following member(s) of "cursor" have conflicts:
synapse/storage/engines/postgres.py:105: note:     description: expected "Optional[Sequence[Tuple[str, Optional[Any], Optional[int], Optional[int], Optional[int], Optional[int], Optional[int]]]]", got "Optional[Tuple[Column, ...]]"
synapse/storage/engines/postgres.py:132: error: Argument 1 of "check_new_database" is incompatible with supertype "BaseDatabaseEngine"; supertype defines the argument type as "cursor"  [override]
synapse/storage/engines/postgres.py:132: note: This violates the Liskov substitution principle
synapse/storage/engines/postgres.py:132: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
tests/server.py:1030: error: Subclass of "Connection" and "connection" cannot exist: would have incompatible method signatures  [unreachable]
tests/server.py:1031: error: Statement is unreachable  [unreachable]
tests/server.py:1077: error: Subclass of "Connection" and "connection" cannot exist: would have incompatible method signatures  [unreachable]
tests/server.py:1078: error: Statement is unreachable  [unreachable]

@DMRobertson
Copy link
Contributor

@DMRobertson
Copy link
Contributor

Guessing that this is python/typeshed#10630.

I think the problem is that I wrote a protocol for Cursor.description

@property
def description(
self,
) -> Optional[
Sequence[
# Note that this is an approximate typing based on sqlite3 and other
# drivers, and may not be entirely accurate.
# FWIW, the DBAPI 2 spec is: https://peps.python.org/pep-0249/#description
Tuple[
str,
Optional[Any],
Optional[int],
Optional[int],
Optional[int],
Optional[int],
Optional[int],
]
]
]:
...

based on https://peps.python.org/pep-0249/#description. But psycopg2 uses a Column type: https://github.com/python/typeshed/blame/d56b0b80d80d4736a21c0dfcc186dfd3ad152bf5/stubs/psycopg2/psycopg2/_psycopg.pyi#L179, rather than an inner tuple like sqlite3: https://github.com/python/typeshed/blob/d56b0b80d80d4736a21c0dfcc186dfd3ad152bf5/stdlib/sqlite3/dbapi2.pyi#L400. (Column defines a getitem so it presumably still looks like a tuple?)

So now mypy can see that psycopg.extensions.cursor doesn't satisfy the protocol I wrote.

I can't see a clean way to fix this, and there's only one call site:

@staticmethod
def cursor_to_dict(cursor: Cursor) -> List[Dict[str, Any]]:
"""Converts a SQL cursor into an list of dicts.
Args:
cursor: The DBAPI cursor which has executed a query.
Returns:
A list of dicts where the key is the column header.
"""
assert cursor.description is not None, "cursor.description was None"
col_headers = [intern(str(column[0])) for column in cursor.description]
results = [dict(zip(col_headers, row)) for row in cursor]
return results

So I'm going to just change description to be Sequence[Any].

@dependabot @github
Copy link
Contributor Author

dependabot bot commented on behalf of github Sep 25, 2023

A newer version of types-psycopg2 exists, but since this PR has been edited by someone other than Dependabot I haven't updated it. You'll get a PR for the updated version as normal once this PR is merged.

@clokep
Copy link
Member

clokep commented Sep 25, 2023

@DMRobertson Is it worth recreating this to see if it works better?

@DMRobertson
Copy link
Contributor

@DMRobertson Is it worth recreating this to see if it works better?

I'd be surprised if it worked without the tweak I added in 3049b8e (#16343), but I'm happy to recreate it and try. We can always resurrect or cherry-pick that change.

@DMRobertson
Copy link
Contributor

@dependabot recreate

@dependabot @github
Copy link
Contributor Author

dependabot bot commented on behalf of github Sep 25, 2023

Superseded by #16381.

@dependabot dependabot bot closed this Sep 25, 2023
@dependabot dependabot bot deleted the dependabot/pip/types-psycopg2-2.9.21.13 branch September 25, 2023 13:09
DMRobertson pushed a commit that referenced this pull request Sep 25, 2023
DMRobertson pushed a commit that referenced this pull request Sep 25, 2023
* Bump types-psycopg2 from 2.9.21.11 to 2.9.21.14

Bumps [types-psycopg2](https://github.com/python/typeshed) from 2.9.21.11 to 2.9.21.14.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-psycopg2
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Relax the annotation of Cursor.description

See
#16343 (comment)
for rationale.

* Changelog

* Changelog

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Robertson <davidr@element.io>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Pull requests from dependabot that update a dependency file python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants