diff --git a/core/src/datayoga_core/blocks/relational/write/block.py b/core/src/datayoga_core/blocks/relational/write/block.py index 153de4e2..b0d42fd5 100644 --- a/core/src/datayoga_core/blocks/relational/write/block.py +++ b/core/src/datayoga_core/blocks/relational/write/block.py @@ -173,8 +173,10 @@ def execute(self, statement: Any, records: List[Dict[str, Any]]): statement = text(statement) logger.debug(f"Executing {statement} on {records}") + connected = False try: with self.engine.connect() as connection: + connected = True try: connection.execute(statement, records) if not connection._is_autocommit_isolation(): @@ -182,7 +184,8 @@ def execute(self, statement: Any, records: List[Dict[str, Any]]): except Exception: raise except Exception as e: - raise ConnectionError(e) from e + if not connected: + raise ConnectionError(e) from e def execute_upsert(self, records: List[Dict[str, Any]]): """Upserts records into the table."""