From 9afe0684da87222fc1fdf2995cb0d2c3e629f95f Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Sun, 13 Mar 2022 10:34:19 -0600 Subject: [PATCH 1/2] Replace `get_status` with `get_response` --- dbt/adapters/mariadb/connections.py | 18 +++++++++--------- dbt/adapters/mysql/connections.py | 18 +++++++++--------- dbt/adapters/mysql5/connections.py | 18 +++++++++--------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/dbt/adapters/mariadb/connections.py b/dbt/adapters/mariadb/connections.py index ad290db..04180f5 100644 --- a/dbt/adapters/mariadb/connections.py +++ b/dbt/adapters/mariadb/connections.py @@ -149,18 +149,18 @@ def exception_handler(self, sql): raise dbt.exceptions.RuntimeException(e) from e - @classmethod - def get_status(cls, cursor): - # There's no real way to get this from mysql-connector-python. - # So just return "OK". - return "OK" - @classmethod def get_response(cls, cursor) -> AdapterResponse: - code = "Unknown cursor state/status" + code = "SUCCESS" + num_rows = 0 + + if cursor is not None and cursor.rowcount is not None: + num_rows = cursor.rowcount + # There's no real way to get the status from the mysql-connector-python driver. + # So just return the default value. return AdapterResponse( - _message="{} {}".format(code, cursor.rowcount), - rows_affected=cursor.rowcount, + _message="{} {}".format(code, num_rows), + rows_affected=num_rows, code=code ) diff --git a/dbt/adapters/mysql/connections.py b/dbt/adapters/mysql/connections.py index 0211bc6..c5cbebf 100644 --- a/dbt/adapters/mysql/connections.py +++ b/dbt/adapters/mysql/connections.py @@ -145,18 +145,18 @@ def exception_handler(self, sql): raise dbt.exceptions.RuntimeException(e) from e - @classmethod - def get_status(cls, cursor): - # There's no real way to get this from mysql-connector-python. - # So just return "OK". - return "OK" - @classmethod def get_response(cls, cursor) -> AdapterResponse: - code = "Unknown cursor state/status" + code = "SUCCESS" + num_rows = 0 + + if cursor is not None and cursor.rowcount is not None: + num_rows = cursor.rowcount + # There's no real way to get the status from the mysql-connector-python driver. + # So just return the default value. return AdapterResponse( - _message="{} {}".format(code, cursor.rowcount), - rows_affected=cursor.rowcount, + _message="{} {}".format(code, num_rows), + rows_affected=num_rows, code=code ) diff --git a/dbt/adapters/mysql5/connections.py b/dbt/adapters/mysql5/connections.py index 1085312..5c51c4e 100644 --- a/dbt/adapters/mysql5/connections.py +++ b/dbt/adapters/mysql5/connections.py @@ -149,18 +149,18 @@ def exception_handler(self, sql): raise dbt.exceptions.RuntimeException(e) from e - @classmethod - def get_status(cls, cursor): - # There's no real way to get this from mysql-connector-python. - # So just return "OK". - return "OK" - @classmethod def get_response(cls, cursor) -> AdapterResponse: - code = "Unknown cursor state/status" + code = "SUCCESS" + num_rows = 0 + + if cursor is not None and cursor.rowcount is not None: + num_rows = cursor.rowcount + # There's no real way to get the status from the mysql-connector-python driver. + # So just return the default value. return AdapterResponse( - _message="{} {}".format(code, cursor.rowcount), - rows_affected=cursor.rowcount, + _message="{} {}".format(code, num_rows), + rows_affected=num_rows, code=code ) From cc979918e54d06613d2b97357df5c7d1bc603eeb Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Sun, 13 Mar 2022 11:03:59 -0600 Subject: [PATCH 2/2] Update CHANGELOG [skip ci] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a507d66..c9f443c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased (TBD) - Support dbt v0.20.0 ([#83](https://github.com/dbeatty10/dbt-mysql/pull/83)) +- Report status as `SUCCESS` instead of `Unknown cursor state/status` ([#84](https://github.com/dbeatty10/dbt-mysql/pull/84)) ## dbt-mysql 0.19.2 (March 12, 2022) - Support dbt v0.19.2 ([#81](https://github.com/dbeatty10/dbt-mysql/pull/81))