Skip to content

Commit

Permalink
Fix cancellation. (#173)
Browse files Browse the repository at this point in the history
### Description

`DatabricksSQLConnectionWrapper` should have `cancel` method and handle it properly.

Otherwise, the following error will be seen when cancelling the session due to e.g., `dbt test --fail-fast`:

```
AttributeError: 'DatabricksSQLConnectionWrapper' object has no attribute 'cancel'
```
  • Loading branch information
ueshin committed Sep 19, 2022
1 parent 2465591 commit ff9423e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## dbt-databricks 1.1.5 (Release TBD)

### Fixes
- Fix cancellation ([#173](https://github.com/databricks/dbt-databricks/pull/173))

## dbt-databricks 1.1.4 (September 8, 2022)

### Fixes
Expand Down
16 changes: 15 additions & 1 deletion dbt/adapters/databricks/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,22 @@ def __init__(self, conn: DatabricksSQLConnection):
def cursor(self) -> "DatabricksSQLCursorWrapper":
return DatabricksSQLCursorWrapper(self._conn.cursor())

def cancel(self) -> None:
cursors: List[DatabricksSQLCursor] = self._conn._cursors

for cursor in cursors:
try:
cursor.cancel()
except DBSQLError as exc:
logger.debug("Exception while cancelling query: {}".format(exc))
_log_dbsql_errors(exc)

def close(self) -> None:
self._conn.close()
try:
self._conn.close()
except DBSQLError as exc:
logger.debug("Exception while closing connection: {}".format(exc))
_log_dbsql_errors(exc)

def rollback(self, *args: Any, **kwargs: Any) -> None:
logger.debug("NotImplemented: rollback")
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/fail_fast/models/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2

models:
- name: view_model
columns:
- name: id
tests:
- unique
- not_null
5 changes: 5 additions & 0 deletions tests/integration/fail_fast/models/view_model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
select 1 as id
union all
select 1 as id
union all
select null as id
37 changes: 37 additions & 0 deletions tests/integration/fail_fast/test_fail_fast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from dbt.exceptions import FailFastException

from tests.integration.base import DBTIntegrationTest, use_profile


class TesFailFast(DBTIntegrationTest):
@property
def schema(self):
return "fail_fast"

@property
def models(self):
return "models"

def test_fail_fast(self):
self.run_dbt(["run"])

with self.assertRaisesRegex(
FailFastException, "Failing early due to test failure or runtime error"
):
self.run_dbt(["test", "--fail-fast"])

@use_profile("databricks_cluster")
def test_fail_fast_databricks_cluster(self):
self.test_fail_fast()

@use_profile("databricks_uc_cluster")
def test_fail_fast_databricks_uc_cluster(self):
self.test_fail_fast()

@use_profile("databricks_sql_endpoint")
def test_fail_fast_databricks_sql_endpoint(self):
self.test_fail_fast()

@use_profile("databricks_uc_sql_endpoint")
def test_fail_fast_databricks_uc_sql_endpoint(self):
self.test_fail_fast()

0 comments on commit ff9423e

Please sign in to comment.