Skip to content

Chore: Remove deprecated pyscopg v2 (pyscopg2) #532

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
11 changes: 9 additions & 2 deletions airbyte/_processors/sql/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import functools

from overrides import overrides
from sqlalchemy import URL

from airbyte._util.name_normalizers import LowerCaseNormalizer
from airbyte._writers.jsonl import JsonlWriter
Expand All @@ -28,9 +29,15 @@ class PostgresConfig(SqlConfig):
@overrides
def get_sql_alchemy_url(self) -> SecretString:
"""Return the SQLAlchemy URL to use."""
return SecretString(
f"postgresql://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}"
url = URL.create(
drivername="postgresql+psycopg",
username=self.username,
password=self.password,
host=self.host,
port=self.port, # defaults to 5432
database=self.database,
)
return SecretString(str(url))

@overrides
def get_database_name(self) -> str:
Expand Down
80 changes: 1 addition & 79 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ orjson = "^3.10"
overrides = "^7.4.0"
pandas = { version = ">=1.5.3,<3.0" }
psycopg = {extras = ["binary", "pool"], version = "^3.1.19"}
psycopg2-binary = "^2.9.9"
pyarrow = ">=16.1,<18.0"
pydantic = ">=2.0,<=3.0"
pydantic-core = "*"
Expand Down
13 changes: 12 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import warnings
from pathlib import Path

from sqlalchemy import URL

import airbyte
import docker
import psycopg
Expand Down Expand Up @@ -125,7 +127,16 @@ def remove_postgres_container():


def test_pg_connection(host) -> bool:
pg_url = f"postgresql://postgres:postgres@{host}:{PYTEST_POSTGRES_PORT}/postgres"
pg_url = str(
URL.create(
drivername="postgresql+psycopg",
username="postgres",
password="postgres",
host=host,
port=PYTEST_POSTGRES_PORT, # defaults to 5432
database="postgres",
)
)

max_attempts = 120
for attempt in range(max_attempts):
Expand Down
Loading