Skip to content

Commit 41a9d99

Browse files
refactor: Switch default driver to psycopg3 (#471)
Related: - #433
1 parent d96acf9 commit 41a9d99

File tree

8 files changed

+187
-70
lines changed

8 files changed

+187
-70
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This target is tested with all actively supported [Python](https://devguide.pyth
3232
| password | False | None | Password used to authenticate. Note if sqlalchemy_url is set this will be ignored. |
3333
| database | False | None | Database name. Note if sqlalchemy_url is set this will be ignored. |
3434
| sqlalchemy_url | False | None | SQLAlchemy connection string. This will override using host, user, password, port, dialect, and all ssl settings. Note that you must escape password special characters properly. See https://docs.sqlalchemy.org/en/20/core/engines.html#escaping-special-characters-such-as-signs-in-passwords |
35-
| dialect+driver | False | postgresql+psycopg2 | Dialect+driver see https://docs.sqlalchemy.org/en/20/core/engines.html. Generally just leave this alone. Note if sqlalchemy_url is set this will be ignored. |
35+
| dialect+driver | False | postgresql+psycopg | Dialect+driver see https://docs.sqlalchemy.org/en/20/core/engines.html. Generally just leave this alone. Note if sqlalchemy_url is set this will be ignored. |
3636
| default_target_schema | False | melty | Postgres schema to send data to, example: tap-clickup |
3737
| activate_version | False | 1 | If set to false, the tap will ignore activate version messages. If set to true, add_record_metadata must be set to true as well. |
3838
| hard_delete | False | 0 | When activate version is sent from a tap this specefies if we should delete the records that don't match, or mark them with a date in the `_sdc_deleted_at` column. This config option is ignored if `activate_version` is set to false. |

poetry.lock

Lines changed: 168 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ packages = [
3434
[tool.poetry.dependencies]
3535
python = ">=3.9"
3636
faker = {version = "~=30.0", optional = true}
37+
psycopg = {extras = ["binary"], version = "3.2.3"}
3738
psycopg2-binary = "2.9.10"
3839
sqlalchemy = "~=2.0"
3940
sshtunnel = "0.4.0"

target_postgres/target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __init__(
150150
th.Property(
151151
"dialect+driver",
152152
th.StringType,
153-
default="postgresql+psycopg2",
153+
default="postgresql+psycopg",
154154
description=(
155155
"Dialect+driver see "
156156
+ "https://docs.sqlalchemy.org/en/20/core/engines.html. "

target_postgres/tests/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def postgres_config():
1010
return {
11-
"dialect+driver": "postgresql+psycopg2",
11+
"dialect+driver": "postgresql+psycopg",
1212
"host": "localhost",
1313
"user": "postgres",
1414
"password": "postgres",
@@ -29,7 +29,7 @@ def postgres_config():
2929

3030
def postgres_config_no_ssl():
3131
return {
32-
"dialect+driver": "postgresql+psycopg2",
32+
"dialect+driver": "postgresql+psycopg",
3333
"host": "localhost",
3434
"user": "postgres",
3535
"password": "postgres",

target_postgres/tests/test_sdk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class BasePostgresSDKTests:
6262
@pytest.fixture()
6363
def connection(self, runner):
6464
engine = create_engine(runner)
65-
return engine.connect()
65+
with engine.connect() as conn:
66+
yield conn
67+
engine.dispose()
6668

6769

6870
SDKTests = get_target_test_class(

target_postgres/tests/test_target_postgres.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def verify_data(
142142
sqlalchemy.text(f"SELECT COUNT(*) FROM {full_table_name}")
143143
)
144144
assert result.first()[0] == number_of_rows
145+
engine.dispose()
145146

146147

147148
def test_sqlalchemy_url_config(postgres_config_no_ssl):
@@ -167,7 +168,7 @@ def test_sqlalchemy_url_config(postgres_config_no_ssl):
167168
def test_port_default_config():
168169
"""Test that the default config is passed into the engine when the config doesn't provide it"""
169170
config = {
170-
"dialect+driver": "postgresql+psycopg2",
171+
"dialect+driver": "postgresql+psycopg",
171172
"host": "localhost",
172173
"user": "postgres",
173174
"password": "postgres",
@@ -186,12 +187,13 @@ def test_port_default_config():
186187
engine.url.render_as_string(hide_password=False)
187188
== f"{dialect_driver}://{user}:{password}@{host}:5432/{database}"
188189
)
190+
engine.dispose()
189191

190192

191193
def test_port_config():
192194
"""Test that the port config works"""
193195
config = {
194-
"dialect+driver": "postgresql+psycopg2",
196+
"dialect+driver": "postgresql+psycopg",
195197
"host": "localhost",
196198
"user": "postgres",
197199
"password": "postgres",
@@ -211,6 +213,7 @@ def test_port_config():
211213
engine.url.render_as_string(hide_password=False)
212214
== f"{dialect_driver}://{user}:{password}@{host}:5433/{database}"
213215
)
216+
engine.dispose()
214217

215218

216219
# Test name would work well
@@ -402,6 +405,7 @@ def test_no_primary_keys(postgres_target):
402405
singer_file_to_target(file_name, postgres_target)
403406

404407
verify_data(postgres_target, table_name, 16)
408+
engine.dispose()
405409

406410

407411
def test_no_type(postgres_target):
@@ -511,6 +515,7 @@ def test_anyof(postgres_target):
511515
# {"anyOf":[{"type":"string"},{"type":"integer"},{"type":"null"}]}
512516
if column.name == "legacy_id":
513517
assert isinstance(column.type, TEXT)
518+
engine.dispose()
514519

515520

516521
def test_new_array_column(postgres_target):
@@ -621,6 +626,7 @@ def test_activate_version_hard_delete(postgres_config_no_ssl):
621626
assert result.rowcount == 9
622627

623628
singer_file_to_target(file_name, pg_hard_delete_true)
629+
engine.dispose()
624630

625631
# Should remove the 2 records we added manually
626632
with engine.connect() as connection:
@@ -692,6 +698,7 @@ def test_activate_version_soft_delete(postgres_config_no_ssl):
692698
# South America row should not have been modified, but it would have been prior
693699
# to the fix mentioned in #204 and implemented in #240.
694700
assert south_america == result.first()._asdict()
701+
engine.dispose()
695702

696703

697704
def test_activate_version_no_metadata(postgres_config_no_ssl):
@@ -742,6 +749,7 @@ def test_activate_version_deletes_data_properly(postgres_target):
742749
with engine.connect() as connection:
743750
result = connection.execute(sqlalchemy.text(f"SELECT * FROM {full_table_name}"))
744751
assert result.rowcount == 0
752+
engine.dispose()
745753

746754

747755
def test_reserved_keywords(postgres_target):

target_postgres/tests/test_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def connector():
1111
"""Create a PostgresConnector instance."""
1212
return PostgresConnector(
1313
config={
14-
"dialect+driver": "postgresql+psycopg2",
14+
"dialect+driver": "postgresql+psycopg",
1515
"host": "localhost",
1616
"port": "5432",
1717
"user": "postgres",

0 commit comments

Comments
 (0)