From 4ab6134e6622e2af245ea638f9ee409daa1a26d5 Mon Sep 17 00:00:00 2001 From: Antonio Carpentieri Date: Mon, 9 Mar 2026 16:18:27 +0100 Subject: [PATCH 1/2] feat: added ENV variables to configure postgresql connection --- README.md | 6 ++++- .../engines/soda/connections/postgres.py | 10 +++---- tests/test_test_postgres.py | 26 ++++++++++++++++++- tests/test_test_quality.py | 10 ++++++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c82dfed1c..1ed7bf3ca 100644 --- a/README.md +++ b/README.md @@ -891,6 +891,10 @@ models: |----------------------------------|--------------------|-------------| | `DATACONTRACT_POSTGRES_USERNAME` | `postgres` | Username | | `DATACONTRACT_POSTGRES_PASSWORD` | `mysecretpassword` | Password | +| `DATACONTRACT_POSTGRES_HOST` | `localhost` | Hostname | +| `DATACONTRACT_POSTGRES_PORT` | `5432` | Port | +| `DATACONTRACT_POSTGRES_DATABASE` | `dbname` | Database name | +| `DATACONTRACT_POSTGRES_SCHEMA` | `public` | Schema | #### Trino @@ -2154,4 +2158,4 @@ Created by [Stefan Negele](https://www.linkedin.com/in/stefan-negele-573153112/) - + \ No newline at end of file diff --git a/datacontract/engines/soda/connections/postgres.py b/datacontract/engines/soda/connections/postgres.py index 29b5c90ce..cfc03f8d4 100644 --- a/datacontract/engines/soda/connections/postgres.py +++ b/datacontract/engines/soda/connections/postgres.py @@ -8,14 +8,14 @@ def to_postgres_soda_configuration(server): soda_configuration = { f"data_source {server.type}": { "type": "postgres", - "host": server.host, - "port": str(server.port), + "host": os.getenv("DATACONTRACT_POSTGRES_HOST", server.host), + "port": os.getenv("DATACONTRACT_POSTGRES_PORT", str(server.port)), "username": os.getenv("DATACONTRACT_POSTGRES_USERNAME"), "password": os.getenv("DATACONTRACT_POSTGRES_PASSWORD"), - "database": server.database, - "schema": server.schema_, + "database": os.getenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + "schema": os.getenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), } } soda_configuration_str = yaml.dump(soda_configuration) - return soda_configuration_str + return soda_configuration_str \ No newline at end of file diff --git a/tests/test_test_postgres.py b/tests/test_test_postgres.py index d5dc573ca..b164d4c4b 100644 --- a/tests/test_test_postgres.py +++ b/tests/test_test_postgres.py @@ -24,6 +24,10 @@ def remove_container(): def test_test_postgres(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/postgres/data/data.sql") datacontract_file = "fixtures/postgres/datacontract.yaml" @@ -40,6 +44,10 @@ def test_test_postgres(postgres_container, monkeypatch): def test_test_postgres_odcs(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/postgres/data/data.sql") datacontract_file = "fixtures/postgres/odcs.yaml" @@ -56,6 +64,10 @@ def test_test_postgres_odcs(postgres_container, monkeypatch): def test_test_postgres_case_sensitive_table_name(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/postgres/data/data_case_sensitive.sql") datacontract_file = "fixtures/postgres/datacontract_case_sensitive.yaml" @@ -72,6 +84,10 @@ def test_test_postgres_case_sensitive_table_name(postgres_container, monkeypatch def test_test_postgres_case_sensitive_table_name_odcs(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/postgres/data/data_case_sensitive.sql") datacontract_file = "fixtures/postgres/odcs_case_sensitive.odcs.yaml" @@ -88,6 +104,10 @@ def test_test_postgres_case_sensitive_table_name_odcs(postgres_container, monkey def test_test_postgres_servicelevels_freshness_should_fail(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/postgres/data/data.sql") datacontract_file = "fixtures/postgres/datacontract_servicelevels.yaml" @@ -103,6 +123,10 @@ def test_test_postgres_servicelevels_freshness_should_fail(postgres_container, m def test_test_postgres_servicelevels_freshness_should_fail_odcs(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/postgres/data/data.sql") datacontract_file = "fixtures/postgres/servicelevels.odcs.yaml" @@ -149,4 +173,4 @@ def _init_sql(file_path): cursor.execute(sql_commands) connection.commit() cursor.close() - connection.close() + connection.close() \ No newline at end of file diff --git a/tests/test_test_quality.py b/tests/test_test_quality.py index 3fac59c18..610943059 100644 --- a/tests/test_test_quality.py +++ b/tests/test_test_quality.py @@ -21,6 +21,10 @@ def remove_container(): def test_test_quality_valid(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/quality/data/data.valid.sql") datacontract_file = "fixtures/quality/datacontract.yaml" data_contract_str = _setup_datacontract(datacontract_file) @@ -36,6 +40,10 @@ def test_test_quality_valid(postgres_container, monkeypatch): def test_test_quality_invalid(postgres_container, monkeypatch): monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username) monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password) + monkeypatch.setenv("DATACONTRACT_POSTGRES_HOST", server.host), + monkeypatch.setenv("DATACONTRACT_POSTGRES_PORT", server.port), + monkeypatch.setenv("DATACONTRACT_POSTGRES_DATABASE", server.database), + monkeypatch.setenv("DATACONTRACT_POSTGRES_SCHEMA", server.schema_), _init_sql("fixtures/quality/data/data.invalid.sql") datacontract_file = "fixtures/quality/datacontract.yaml" data_contract_str = _setup_datacontract(datacontract_file) @@ -98,4 +106,4 @@ def _init_sql(file_path): cursor.execute(sql_commands) connection.commit() cursor.close() - connection.close() + connection.close() \ No newline at end of file From 1a984ca0a0db1aa94b1a670f78c4887e5e49bbfc Mon Sep 17 00:00:00 2001 From: Antonio Carpentieri Date: Thu, 19 Mar 2026 17:34:06 +0100 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1ed7bf3ca..c0884b339 100644 --- a/README.md +++ b/README.md @@ -891,10 +891,10 @@ models: |----------------------------------|--------------------|-------------| | `DATACONTRACT_POSTGRES_USERNAME` | `postgres` | Username | | `DATACONTRACT_POSTGRES_PASSWORD` | `mysecretpassword` | Password | -| `DATACONTRACT_POSTGRES_HOST` | `localhost` | Hostname | -| `DATACONTRACT_POSTGRES_PORT` | `5432` | Port | -| `DATACONTRACT_POSTGRES_DATABASE` | `dbname` | Database name | -| `DATACONTRACT_POSTGRES_SCHEMA` | `public` | Schema | +| `DATACONTRACT_POSTGRES_HOST` | `localhost` | Hostname | +| `DATACONTRACT_POSTGRES_PORT` | `5432` | Port | +| `DATACONTRACT_POSTGRES_DATABASE` | `dbname` | Database | +| `DATACONTRACT_POSTGRES_SCHEMA` | `public` | Schema | #### Trino