From 3136d5a0f8c2788a7bda8a95b22e77d2bfe47cfc Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Mon, 8 Jun 2026 14:07:03 +0000 Subject: [PATCH] use correct db session to write to db --- .../local_handler/invoke_local_orchestrator.py | 4 ++-- orchestration/magic_plan_orchestrator.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/applications/magic_plan/local_handler/invoke_local_orchestrator.py b/applications/magic_plan/local_handler/invoke_local_orchestrator.py index ed07ffde..2a1e561e 100644 --- a/applications/magic_plan/local_handler/invoke_local_orchestrator.py +++ b/applications/magic_plan/local_handler/invoke_local_orchestrator.py @@ -27,8 +27,8 @@ from infrastructure.s3.s3_client import S3Client from orchestration.magic_plan_orchestrator import MagicPlanOrchestrator from applications.magic_plan.magic_plan_trigger_request import MagicPlanTriggerRequest -ADDRESS = "63 Dunkery Road, Wythenshawe, M22 0WR | EPC" -HUBSPOT_DEAL_ID = "501851906250" +ADDRESS = "20 Larch Way, Bromley, BR2 8DU | Retrofit Assessment" +HUBSPOT_DEAL_ID = "500328089833" # ADDRESS = "33 Wallaby Way, Sydney" # HUBSPOT_DEAL_ID = "123456789" diff --git a/orchestration/magic_plan_orchestrator.py b/orchestration/magic_plan_orchestrator.py index 4d1f5c38..a3191985 100644 --- a/orchestration/magic_plan_orchestrator.py +++ b/orchestration/magic_plan_orchestrator.py @@ -15,7 +15,7 @@ from backend.app.db.models.uploaded_file import ( ) from applications.magic_plan.address_matcher import find_matching_plan from infrastructure.postgres.config import PostgresConfig -from infrastructure.postgres.engine import make_engine, make_session +from infrastructure.postgres.engine import make_engine, transactional_session from infrastructure.s3.s3_client import S3Client from repositories.magic_plan.magic_plan_postgres_repository import ( MagicPlanPostgresRepository, @@ -69,13 +69,12 @@ class MagicPlanOrchestrator: logger.info("Successfully save Plan json") engine = make_engine(PostgresConfig.from_env(os.environ)) - session = make_session(engine) - - session.add(uploaded_file) - session.flush() - MagicPlanPostgresRepository(session).save( - plan, cast(int, uploaded_file.id) - ) # TODO: refactor to use postgres Unit of Work + with transactional_session(engine) as session: + session.add(uploaded_file) + session.flush() + MagicPlanPostgresRepository(session).save( + plan, cast(int, uploaded_file.id) + ) # TODO: refactor to use postgres Unit of Work logger.info("Successfully saved Plan to database") return plan