Repository: TobikoData/sqlmesh
Pull request #2594 (2024-05-11 02:07:57)

chore: support dbt 1.8


Patch:
diff --git a/sqlmesh/dbt/adapter.py b/sqlmesh/dbt/adapter.py
index 463ecb06..d955317c 100644
--- a/sqlmesh/dbt/adapter.py
+++ b/sqlmesh/dbt/adapter.py
@@ -5,7 +5,6 @@ import logging
 import typing as t
 
 import pandas as pd
-from dbt.contracts.relation import Policy
 from sqlglot import exp, parse_one
 
 from sqlmesh.core.dialect import normalize_and_quote, normalize_model_name
@@ -19,6 +18,7 @@ if t.TYPE_CHECKING:
     from dbt.adapters.base import BaseRelation
     from dbt.adapters.base.column import Column
     from dbt.adapters.base.impl import AdapterResponse
+    from sqlmesh.dbt.relation import Policy
 
 
 logger = logging.getLogger(__name__)
@@ -221,7 +221,7 @@ class RuntimeAdapter(BaseAdapter):
         return self.list_relations_without_caching(reference_relation)
 
     def list_relations_without_caching(self, schema_relation: BaseRelation) -> t.List[BaseRelation]:
-        from dbt.contracts.relation import RelationType
+        from sqlmesh.dbt.relation import RelationType
 
         schema = self._normalize(self._schema(schema_relation))
 
diff --git a/sqlmesh/dbt/basemodel.py b/sqlmesh/dbt/basemodel.py
index 1e11ae90..7417562f 100644
--- a/sqlmesh/dbt/basemodel.py
+++ b/sqlmesh/dbt/basemodel.py
@@ -5,7 +5,6 @@ from abc import abstractmethod
 from enum import Enum
 from pathlib import Path
 
-from dbt.contracts.relation import Policy, RelationType
 from pydantic import Field
 from sqlglot.helper import ensure_list
 
@@ -24,6 +23,7 @@ from sqlmesh.dbt.common import (
     SqlStr,
     sql_str_validator,
 )
+from sqlmesh.dbt.relation import Policy, RelationType
 from sqlmesh.dbt.test import TestConfig
 from sqlmesh.utils import AttributeDict
 from sqlmesh.utils.conversions import ensure_bool
diff --git a/sqlmesh/dbt/builtin.py b/sqlmesh/dbt/builtin.py
index ed2779b1..d95bd09d 100644
--- a/sqlmesh/dbt/builtin.py
+++ b/sqlmesh/dbt/builtin.py
@@ -11,11 +11,11 @@ import agate
 import jinja2
 from dbt import version
 from dbt.adapters.base import BaseRelation, Column
-from dbt.contracts.relation import Policy
 from ruamel.yaml import YAMLError
 
 from sqlmesh.core.engine_adapter import EngineAdapter
 from sqlmesh.dbt.adapter import BaseAdapter, ParsetimeAdapter, RuntimeAdapter
+from sqlmesh.dbt.relation import Policy
 from sqlmesh.dbt.target import TARGET_TYPE_TO_CONFIG_CLASS
 from sqlmesh.dbt.util import DBT_VERSION
 from sqlmesh.utils import AttributeDict, yaml
diff --git a/sqlmesh/dbt/context.py b/sqlmesh/dbt/context.py
index c8a853a7..855cfaf0 100644
--- a/sqlmesh/dbt/context.py
+++ b/sqlmesh/dbt/context.py
@@ -20,11 +20,11 @@ from sqlmesh.utils.jinja import (
 )
 
 if t.TYPE_CHECKING:
-    from dbt.contracts.relation import Policy
     from jinja2 import Environment
 
     from sqlmesh.dbt.basemodel import Dependencies
     from sqlmesh.dbt.model import ModelConfig
+    from sqlmesh.dbt.relation import Policy
     from sqlmesh.dbt.seed import SeedConfig
     from sqlmesh.dbt.source import SourceConfig
 
diff --git a/sqlmesh/dbt/relation.py b/sqlmesh/dbt/relation.py
new file mode 100644
index 00000000..11708bc4
--- /dev/null
+++ b/sqlmesh/dbt/relation.py
@@ -0,0 +1,7 @@
+from sqlmesh.dbt.util import DBT_VERSION
+
+
+if DBT_VERSION < (1, 8):
+    from dbt.contracts.relation import *  # noqa: F403
+else:
+    from dbt.adapters.contracts.relation import *  # noqa: F403
diff --git a/sqlmesh/dbt/source.py b/sqlmesh/dbt/source.py
index 14d33332..39651ce7 100644
--- a/sqlmesh/dbt/source.py
+++ b/sqlmesh/dbt/source.py
@@ -2,12 +2,12 @@ from __future__ import annotations
 
 import typing as t
 
-from dbt.contracts.relation import RelationType
 from pydantic import Field
 
 from sqlmesh.core.config.base import UpdateStrategy
 from sqlmesh.dbt.column import ColumnConfig
 from sqlmesh.dbt.common import GeneralConfig
+from sqlmesh.dbt.relation import RelationType
 from sqlmesh.utils import AttributeDict
 from sqlmesh.utils.errors import ConfigError
 
diff --git a/sqlmesh/dbt/target.py b/sqlmesh/dbt/target.py
index 993af1a3..70c54407 100644
--- a/sqlmesh/dbt/target.py
+++ b/sqlmesh/dbt/target.py
@@ -7,7 +7,6 @@ import typing as t
 from pathlib import Path
 
 from dbt.adapters.base import BaseRelation, Column
-from dbt.contracts.relation import Policy
 from pydantic import Field
 
 from sqlmesh.core.config.connection import (
@@ -30,6 +29,7 @@ from sqlmesh.core.model import (
     IncrementalUnmanagedKind,
 )
 from sqlmesh.dbt.common import DbtConfig
+from sqlmesh.dbt.relation import Policy
 from sqlmesh.dbt.util import DBT_VERSION
 from sqlmesh.utils import AttributeDict, classproperty
 from sqlmesh.utils.errors import ConfigError


Test patch:
diff --git a/tests/dbt/test_adapter.py b/tests/dbt/test_adapter.py
index 644b2080..c6e91f37 100644
--- a/tests/dbt/test_adapter.py
+++ b/tests/dbt/test_adapter.py
@@ -8,7 +8,6 @@ from unittest.mock import call
 import pytest
 from dbt.adapters.base import BaseRelation
 from dbt.adapters.base.column import Column
-from dbt.contracts.relation import Policy
 from pytest_mock.plugin import MockerFixture
 from sqlglot import exp
 
@@ -16,6 +15,7 @@ from sqlmesh import Context
 from sqlmesh.core.dialect import schema_
 from sqlmesh.core.snapshot import SnapshotId
 from sqlmesh.dbt.project import Project
+from sqlmesh.dbt.relation import Policy
 from sqlmesh.dbt.target import SnowflakeConfig
 from sqlmesh.utils.errors import ConfigError
 
diff --git a/tests/dbt/test_config.py b/tests/dbt/test_config.py
index 16e7bf16..f434e126 100644
--- a/tests/dbt/test_config.py
+++ b/tests/dbt/test_config.py
@@ -6,7 +6,6 @@ from unittest.mock import PropertyMock
 
 import pytest
 from dbt.adapters.base import BaseRelation, Column
-from dbt.contracts.relation import Policy
 from pytest_mock import MockerFixture
 
 from sqlmesh.core.dialect import jinja_query
@@ -16,6 +15,7 @@ from sqlmesh.dbt.context import DbtContext
 from sqlmesh.dbt.loader import sqlmesh_config
 from sqlmesh.dbt.model import IncrementalByUniqueKeyKind, Materialization, ModelConfig
 from sqlmesh.dbt.project import Project
+from sqlmesh.dbt.relation import Policy
 from sqlmesh.dbt.source import SourceConfig
 from sqlmesh.dbt.target import (
     TARGET_TYPE_TO_CONFIG_CLASS,
diff --git a/tests/dbt/test_transformation.py b/tests/dbt/test_transformation.py
index cd1843c3..f613d761 100644
--- a/tests/dbt/test_transformation.py
+++ b/tests/dbt/test_transformation.py
@@ -6,7 +6,6 @@ from unittest.mock import patch
 
 import pytest
 from dbt.adapters.base import BaseRelation
-from dbt.contracts.relation import Policy
 from dbt.exceptions import CompilationError
 from freezegun import freeze_time
 from pytest_mock.plugin import MockerFixture
@@ -35,6 +34,7 @@ from sqlmesh.dbt.column import (
 from sqlmesh.dbt.context import DbtContext
 from sqlmesh.dbt.model import Materialization, ModelConfig
 from sqlmesh.dbt.project import Project
+from sqlmesh.dbt.relation import Policy
 from sqlmesh.dbt.seed import SeedConfig
 from sqlmesh.dbt.target import BigQueryConfig, DuckDbConfig, SnowflakeConfig
 from sqlmesh.dbt.test import TestConfig