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

Commit

Permalink
synapse.storage.engines: use psycopg2cffi compat hook
Browse files Browse the repository at this point in the history
Plainly importing psycopg2cffi as psycopg2 is inadequate, because
psycopg2 or its components (psycopg2.extras) are being also imported
elsewhere and patching them all is prone to breakage.

Fixes #5054.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
  • Loading branch information
intelfx committed Jan 30, 2021
1 parent f2c1560 commit ca39247
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/9270.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore PyPy compatibility by using psycopg2cffi consistently.
8 changes: 5 additions & 3 deletions synapse/storage/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def create_engine(database_config) -> BaseDatabaseEngine:
if name == "psycopg2":
# pypy requires psycopg2cffi rather than psycopg2
if platform.python_implementation() == "PyPy":
import psycopg2cffi as psycopg2 # type: ignore
else:
import psycopg2 # type: ignore
from psycopg2cffi import compat # type: ignore

compat.register()

import psycopg2 # type: ignore

return PostgresEngine(psycopg2, database_config)

Expand Down

0 comments on commit ca39247

Please sign in to comment.