Skip to content

Commit df5a0d2

Browse files
authored
Test (#707)
* Revert "Bump psycopg to 3.2.1 (#696)" This reverts commit a561690 * Revert "Update helper for psycopg3 (#706)" This reverts commit d4474f7. * Revert "Change test url" This reverts commit db59063. * Revert "Fix Psycopg3 errors (#698)" This reverts commit 72ad36e
1 parent 2ada7e4 commit df5a0d2

File tree

8 files changed

+24
-49
lines changed

8 files changed

+24
-49
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.5.2
2+
current_version = 2.6.0
33
commit = False
44
tag = False
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(rc(?P<build>\d+))?

.github/workflows/run-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
env:
5252
FLIT_ROOT_INSTALL: 1
5353
- name: Run Unit tests
54-
run: CACHE_URI=redis://redis DATABASE_URI=postgresql+psycopg://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB pytest --cov-branch --cov=orchestrator --cov-report=xml --ignore=test --ignore=orchestrator/devtools --ignore=examples --ignore=docs --ignore=orchestrator/vendor
54+
run: CACHE_URI=redis://redis DATABASE_URI=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB pytest --cov-branch --cov=orchestrator --cov-report=xml --ignore=test --ignore=orchestrator/devtools --ignore=examples --ignore=docs --ignore=orchestrator/vendor
5555
env:
5656
POSTGRES_DB: orchestrator-core-test
5757
POSTGRES_USER: nwa

orchestrator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
"""This is the orchestrator workflow engine."""
1515

16-
__version__ = "2.5.2"
16+
__version__ = "2.6.0"
1717

1818
from orchestrator.app import OrchestratorCore
1919
from orchestrator.settings import app_settings

orchestrator/cli/generator/generator/migration.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,13 @@
3131
sort_product_blocks_by_dependencies,
3232
)
3333
from orchestrator.cli.generator.generator.settings import product_generator_settings as settings
34-
from orchestrator.settings import convert_database_uri
3534

3635
logger = structlog.getLogger(__name__)
3736

3837

3938
def create_migration_file(message: str, head: str) -> Path | None:
40-
if environ.get("DATABASE_URI"):
41-
environ.update({"DATABASE_URI": convert_database_uri(environ["DATABASE_URI"])})
42-
else:
43-
environ.update({"DATABASE_URI": "postgresql+psycopg://nwa:nwa@localhost/orchestrator-core"})
39+
if not environ.get("DATABASE_URI"):
40+
environ.update({"DATABASE_URI": "postgresql://nwa:nwa@localhost/orchestrator-core"})
4441
if not environ.get("PYTHONPATH"):
4542
environ.update({"PYTHONPATH": "."})
4643
logger.info(

orchestrator/migrations/helpers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def create_resource_types_for_product_blocks(conn: sa.engine.Connection, new: di
450450
WITH resource_type_ids AS (
451451
SELECT resource_types.resource_type_id
452452
FROM resource_types
453-
WHERE resource_types.resource_type = ANY(:new_resource_types)
453+
WHERE resource_types.resource_type IN :new_resource_types
454454
), service_attach_point AS (
455455
SELECT product_blocks.product_block_id
456456
FROM product_blocks
@@ -470,7 +470,7 @@ def create_resource_types_for_product_blocks(conn: sa.engine.Connection, new: di
470470
),
471471
{
472472
"product_block_name": product_block,
473-
"new_resource_types": list(resource_types.keys()),
473+
"new_resource_types": tuple(resource_types.keys()),
474474
},
475475
)
476476
return resource_type_ids
@@ -795,11 +795,11 @@ def delete_resource_types_from_product_blocks(conn: sa.engine.Connection, delete
795795
USING resource_types
796796
WHERE product_block_id = (SELECT product_block_id FROM product_blocks WHERE name=:product_block_name) AND
797797
resource_types.resource_type_id = product_block_resource_types.resource_type_id AND
798-
resource_types.resource_type = ANY(:obsolete_resource_types)"""
798+
resource_types.resource_type IN :obsolete_resource_types"""
799799
),
800800
{
801801
"product_block_name": product_block_name,
802-
"obsolete_resource_types": list(resource_types.keys()),
802+
"obsolete_resource_types": tuple(resource_types.keys()),
803803
},
804804
)
805805

@@ -820,11 +820,11 @@ def delete_resource_types(conn: sa.engine.Connection, delete: Iterable) -> None:
820820
"""DELETE FROM product_block_resource_types
821821
USING resource_types
822822
WHERE resource_types.resource_type_id = product_block_resource_types.resource_type_id
823-
AND resource_types.resource_type = ANY(:obsolete)"""
823+
AND resource_types.resource_type IN :obsolete"""
824824
),
825-
{"obsolete": list(delete)},
825+
{"obsolete": tuple(delete)},
826826
)
827-
conn.execute(sa.text("DELETE FROM resource_types WHERE resource_type = ANY(:obsolete)"), {"obsolete": list(delete)})
827+
conn.execute(sa.text("DELETE FROM resource_types WHERE resource_type in :obsolete;"), {"obsolete": tuple(delete)})
828828

829829

830830
def delete_products_by_tag(conn: sa.engine.Connection, name: str) -> None:
@@ -1028,11 +1028,11 @@ def convert_resource_type_relations_to_instance_relations(
10281028
)
10291029
SELECT
10301030
in_use_by_instance_id AS in_use_by_id,
1031-
sii.subscription_instance_id AS depends_on_id,
1032-
(row_number() OVER (PARTITION BY in_use_by_instance_id) - 1) AS order_id,
1031+
si.subscription_instance_id AS depends_on_id,
1032+
(row_number() OVER (PARTITION BY in_use_by_id) - 1) AS order_id,
10331033
:domain_model_attr AS domain_model_attr
1034-
FROM subscription_instances AS sii
1035-
INNER JOIN dependencies AS dep ON sii.subscription_id=uuid(dep.subscription_id) ON CONFLICT DO NOTHING
1034+
FROM subscription_instances AS si
1035+
INNER JOIN dependencies AS dep ON si.subscription_id=uuid(dep.subscription_id) ON CONFLICT DO NOTHING
10361036
"""
10371037
),
10381038
{

orchestrator/settings.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import secrets
1515
import string
16-
import warnings
1716
from pathlib import Path
1817

1918
from pydantic import PostgresDsn, RedisDsn
@@ -23,10 +22,6 @@
2322
from orchestrator.types import strEnum
2423

2524

26-
class OrchestratorDeprecationWarning(DeprecationWarning):
27-
pass
28-
29-
3025
class ExecutorType(strEnum):
3126
WORKER = "celery"
3227
THREADPOOL = "threadpool"
@@ -53,7 +48,7 @@ class AppSettings(BaseSettings):
5348
EXECUTOR: str = ExecutorType.THREADPOOL
5449
WORKFLOWS_SWAGGER_HOST: str = "localhost"
5550
WORKFLOWS_GUI_URI: str = "http://localhost:3000"
56-
DATABASE_URI: PostgresDsn = "postgresql+psycopg://nwa:nwa@localhost/orchestrator-core" # type: ignore
51+
DATABASE_URI: PostgresDsn = "postgresql://nwa:nwa@localhost/orchestrator-core" # type: ignore
5752
MAX_WORKERS: int = 5
5853
MAIL_SERVER: str = "localhost"
5954
MAIL_PORT: int = 25
@@ -84,21 +79,6 @@ class AppSettings(BaseSettings):
8479
DEFAULT_CUSTOMER_IDENTIFIER: str = "59289a57-70fb-4ff5-9c93-10fe67b12434"
8580
TASK_LOG_RETENTION_DAYS: int = 3
8681

87-
def __init__(self) -> None:
88-
super(AppSettings, self).__init__()
89-
self.DATABASE_URI = PostgresDsn(convert_database_uri(str(self.DATABASE_URI)))
90-
91-
92-
def convert_database_uri(db_uri: str) -> str:
93-
if db_uri.startswith(("postgresql://", "postgresql+psycopg2://")):
94-
db_uri = "postgresql+psycopg" + db_uri[db_uri.find("://") :]
95-
warnings.filterwarnings("always", category=OrchestratorDeprecationWarning)
96-
warnings.warn( # noqa: B028
97-
"DATABASE_URI converted to postgresql+psycopg:// format, please update your enviroment variable",
98-
OrchestratorDeprecationWarning,
99-
)
100-
return db_uri
101-
10282

10383
app_settings = AppSettings()
10484

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies = [
4646
"itsdangerous",
4747
"Jinja2==3.1.4",
4848
"orjson==3.10.6",
49-
"psycopg[binary]==3.2.1",
49+
"psycopg2-binary==2.9.9",
5050
"pydantic[email]~=2.7.4",
5151
"pydantic-settings~=2.3.1",
5252
"python-dateutil==2.8.2",

test/unit_tests/conftest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def db_uri(worker_id):
167167
Database uri to be used in the test thread
168168
169169
"""
170-
database_uri = os.environ.get("DATABASE_URI", "postgresql+psycopg://nwa:nwa@localhost/orchestrator-core-test")
170+
database_uri = os.environ.get("DATABASE_URI", "postgresql://nwa:nwa@localhost/orchestrator-core-test")
171171
if worker_id == "master":
172172
# pytest is being run without any workers
173173
return database_uri
@@ -198,9 +198,9 @@ def database(db_uri):
198198
url.database = "postgres"
199199
engine = create_engine(url)
200200
with closing(engine.connect()) as conn:
201-
conn.commit()
202-
conn.execution_options(isolation_level="AUTOCOMMIT").execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
203-
conn.commit()
201+
conn.execute(text("COMMIT;"))
202+
conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
203+
conn.execute(text("COMMIT;"))
204204
conn.execute(text(f'CREATE DATABASE "{db_to_create}";'))
205205

206206
run_migrations(db_uri)
@@ -211,10 +211,8 @@ def database(db_uri):
211211
finally:
212212
db.wrapped_database.engine.dispose()
213213
with closing(engine.connect()) as conn:
214-
conn.commit()
215-
conn.execution_options(isolation_level="AUTOCOMMIT").execute(
216-
text(f'DROP DATABASE IF EXISTS "{db_to_create}";')
217-
)
214+
conn.execute(text("COMMIT;"))
215+
conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
218216

219217

220218
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)