diff --git a/dbt/adapters/tidb/__version__.py b/dbt/adapters/tidb/__version__.py index d28b3dd..cd70cb0 100644 --- a/dbt/adapters/tidb/__version__.py +++ b/dbt/adapters/tidb/__version__.py @@ -1 +1 @@ -version = "1.3.0" +version = "1.6.4" diff --git a/dbt/adapters/tidb/connections.py b/dbt/adapters/tidb/connections.py index fa1a991..de67161 100644 --- a/dbt/adapters/tidb/connections.py +++ b/dbt/adapters/tidb/connections.py @@ -40,7 +40,7 @@ def __init__(self, **kwargs): def __post_init__(self): # mysql classifies database and schema as the same thing if self.database is not None and self.database != self.schema: - raise dbt.exceptions.RuntimeException( + raise dbt.exceptions.DbtRuntimeError( f" schema: {self.schema} \n" f" database: {self.database} \n" f"On TiDB, database must be omitted or have the same value as" @@ -126,19 +126,19 @@ def exception_handler(self, sql): logger.debug("Failed to release connection!") pass - raise dbt.exceptions.DatabaseException(str(e).strip()) from e + raise dbt.exceptions.DbtDatabaseError(str(e).strip()) from e except Exception as e: logger.debug("Error running SQL: {}", sql) logger.debug("Rolling back transaction.") self.rollback_if_open() - if isinstance(e, dbt.exceptions.RuntimeException): + if isinstance(e, dbt.exceptions.DbtRuntimeError): # during a sql query, an internal to dbt exception was raised. # this sounds a lot like a signal handler and probably has # useful information, so raise it without modification. raise - raise dbt.exceptions.RuntimeException(e) from e + raise dbt.exceptions.DbtRuntimeError(e) from e @classmethod def get_response(cls, cursor) -> AdapterResponse: diff --git a/dbt/adapters/tidb/impl.py b/dbt/adapters/tidb/impl.py index afe2eeb..d545fcc 100644 --- a/dbt/adapters/tidb/impl.py +++ b/dbt/adapters/tidb/impl.py @@ -49,7 +49,7 @@ def list_relations_without_caching( kwargs = {"schema_relation": schema_relation} try: results = self.execute_macro(LIST_RELATIONS_MACRO_NAME, kwargs=kwargs) - except dbt.exceptions.RuntimeException as e: + except dbt.exceptions.DbtRuntimeError as e: errmsg = getattr(e, "msg", "") if f"TiDB database '{schema_relation}' not found" in errmsg: return [] @@ -61,7 +61,7 @@ def list_relations_without_caching( relations = [] for row in results: if len(row) != 4: - raise dbt.exceptions.RuntimeException( + raise dbt.exceptions.DbtRuntimeError( "Invalid value from " f'"tidb__list_relations_without_caching({kwargs})", ' f"got {len(row)} values, expected 4" @@ -94,7 +94,7 @@ def _get_columns_for_catalog( def get_relation( self, database: str, schema: str, identifier: str ) -> Optional[BaseRelation]: - if not self.Relation.include_policy.database: + if not self.Relation.get_default_include_policy().database: database = None return super().get_relation(database, schema, identifier) @@ -121,7 +121,7 @@ def get_catalog(self, manifest): schema_map = self._get_catalog_schemas(manifest) if len(schema_map) > 1: - dbt.exceptions.raise_compiler_error( + raise dbt.exceptions.CompilationError( f"Expected only one database in get_catalog, found " f"{list(schema_map)}" ) @@ -150,7 +150,7 @@ def _get_one_catalog( manifest, ) -> agate.Table: if len(schemas) != 1: - dbt.exceptions.raise_compiler_error( + raise dbt.exceptions.CompilationError( f"Expected only one schema in tidb _get_one_catalog, found " f"{schemas}" ) @@ -160,7 +160,7 @@ def _get_one_catalog( columns: List[Dict[str, Any]] = [] for relation in self.list_relations(database, schema): - logger.debug("Getting table schema for relation {}", relation) + logger.debug("Getting table schema for relation {}", str(relation)) columns.extend(self._get_columns_for_catalog(relation)) return agate.Table.from_object(columns, column_types=DEFAULT_TYPE_TESTER) @@ -205,7 +205,7 @@ def string_add_sql( elif location == "prepend": return f"concat({value}, '{add_to}')" else: - raise dbt.exceptions.RuntimeException( + raise dbt.exceptions.DbtRuntimeError( f'Got an unexpected location value of "{location}"' ) diff --git a/dbt/adapters/tidb/relation.py b/dbt/adapters/tidb/relation.py index 359faa8..8543398 100644 --- a/dbt/adapters/tidb/relation.py +++ b/dbt/adapters/tidb/relation.py @@ -1,7 +1,7 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from dbt.adapters.base.relation import BaseRelation, Policy -from dbt.exceptions import RuntimeException +from dbt.exceptions import DbtRuntimeError @dataclass @@ -20,17 +20,17 @@ class TiDBIncludePolicy(Policy): @dataclass(frozen=True, eq=False, repr=False) class TiDBRelation(BaseRelation): - quote_policy: TiDBQuotePolicy = TiDBQuotePolicy() - include_policy: TiDBIncludePolicy = TiDBIncludePolicy() + quote_policy: TiDBQuotePolicy = field(default_factory=lambda: TiDBQuotePolicy()) + include_policy: TiDBIncludePolicy = field(default_factory=lambda: TiDBIncludePolicy()) quote_character: str = "`" def __post_init__(self): if self.database != self.schema and self.database: - raise RuntimeException(f"Cannot set database {self.database} in tidb!") + raise DbtRuntimeError(f"Cannot set database {self.database} in tidb!") def render(self): if self.include_policy.database and self.include_policy.schema: - raise RuntimeException( + raise DbtRuntimeError( "Got a tidb relation with schema and database set to " "include, but only one can be set" ) diff --git a/requirements_dev.txt b/requirements_dev.txt index edafd16..0ef8daf 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,6 +1,6 @@ -dbt-core~=1.3.1 -mysql-connector-python>=8.0.0,<8.1 +dbt-core~=1.6.4 +mysql-connector-python>=8.0.0,<8.2 pytest~=7.0 markupsafe==2.0.1 -dbt-tests-adapter~=1.3.1 -pytest-dotenv \ No newline at end of file +dbt-tests-adapter~=1.6.4 +pytest-dotenv diff --git a/setup.py b/setup.py index ab2183b..702d5d0 100644 --- a/setup.py +++ b/setup.py @@ -2,9 +2,9 @@ import os import sys -if sys.version_info < (3, 8) or sys.version_info >= (3, 11): +if sys.version_info < (3, 8): print("Error: dbt-tidb does not support this version of Python.") - print("Please install Python 3.8 or higher but less than 3.11.") + print("Please install Python 3.8 or higher.") sys.exit(1) # require version of setuptools that supports find_namespace_packages @@ -27,8 +27,8 @@ long_description = f.read() package_name = "dbt-tidb" -package_version = "1.3.0" -dbt_core_version = "1.3.1" +package_version = "1.6.4" +dbt_core_version = "1.6.4" description = """The TiDB adapter plugin for dbt""" setup( @@ -44,7 +44,7 @@ include_package_data=True, install_requires=[ "dbt-core~={}".format(dbt_core_version), - "mysql-connector-python>=8.0.0,<8.1", + "mysql-connector-python>=8.0.0,<8.2", ], zip_safe=False, classifiers=[ @@ -56,6 +56,7 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", ], - python_requires=">=3.8,<=3.10", + python_requires=">=3.8", )