Repository: dbt-labs/dbt-core

Issue:
[CT-3279] Remove usage of dbt.config in dbt/adapters



Discussion:

Resolving patch:
diff --git a/core/dbt/adapters/base/plugin.py b/core/dbt/adapters/base/plugin.py
--- a/core/dbt/adapters/base/plugin.py
+++ b/core/dbt/adapters/base/plugin.py
@@ -1,20 +1,10 @@
 from typing import List, Optional, Type
+from pathlib import Path
 
 from dbt.adapters.base import Credentials
-from dbt.exceptions import CompilationError
 from dbt.adapters.protocol import AdapterProtocol
 
 
-def project_name_from_path(include_path: str) -> str:
-    # avoid an import cycle
-    from dbt.config.project import PartialProject
-
-    partial = PartialProject.from_project_root(include_path)
-    if partial.project_name is None:
-        raise CompilationError(f"Invalid project at {include_path}: name not set!")
-    return partial.project_name
-
-
 class AdapterPlugin:
     """Defines the basic requirements for a dbt adapter plugin.
 
@@ -29,12 +19,13 @@ def __init__(
         credentials: Type[Credentials],
         include_path: str,
         dependencies: Optional[List[str]] = None,
+        project_name: Optional[str] = None,
     ) -> None:
 
         self.adapter: Type[AdapterProtocol] = adapter
         self.credentials: Type[Credentials] = credentials
         self.include_path: str = include_path
-        self.project_name: str = project_name_from_path(include_path)
+        self.project_name: str = project_name or f"dbt_{Path(include_path).name}"
         self.dependencies: List[str]
         if dependencies is None:
             self.dependencies = []


Test patch:
diff --git a/tests/unit/test_adapter_factory.py b/tests/unit/test_adapter_factory.py
--- a/tests/unit/test_adapter_factory.py
+++ b/tests/unit/test_adapter_factory.py
@@ -10,33 +10,32 @@
 
 class TestGetPackageNames(unittest.TestCase):
     def setUp(self):
-        with mock.patch("dbt.adapters.base.plugin.project_name_from_path") as get_name:
-            get_name.return_value = "root"
-            self.root_plugin = AdapterPlugin(
-                adapter=mock.MagicMock(),
-                credentials=mock.MagicMock(),
-                include_path="/path/to/root/plugin",
-                dependencies=["childa", "childb"],
-            )
-            get_name.return_value = "pkg_childa"
-            self.childa = AdapterPlugin(
-                adapter=mock.MagicMock(),
-                credentials=mock.MagicMock(),
-                include_path="/path/to/childa",
-            )
-            get_name.return_value = "pkg_childb"
-            self.childb = AdapterPlugin(
-                adapter=mock.MagicMock(),
-                credentials=mock.MagicMock(),
-                include_path="/path/to/childb",
-                dependencies=["childc"],
-            )
-            get_name.return_value = "pkg_childc"
-            self.childc = AdapterPlugin(
-                adapter=mock.MagicMock(),
-                credentials=mock.MagicMock(),
-                include_path="/path/to/childc",
-            )
+        self.root_plugin = AdapterPlugin(
+            adapter=mock.MagicMock(),
+            credentials=mock.MagicMock(),
+            include_path="/path/to/root/plugin",
+            dependencies=["childa", "childb"],
+            project_name="root",
+        )
+        self.childa = AdapterPlugin(
+            adapter=mock.MagicMock(),
+            credentials=mock.MagicMock(),
+            include_path="/path/to/childa",
+            project_name="pkg_childa",
+        )
+        self.childb = AdapterPlugin(
+            adapter=mock.MagicMock(),
+            credentials=mock.MagicMock(),
+            include_path="/path/to/childb",
+            dependencies=["childc"],
+            project_name="pkg_childb",
+        )
+        self.childc = AdapterPlugin(
+            adapter=mock.MagicMock(),
+            credentials=mock.MagicMock(),
+            include_path="/path/to/childc",
+            project_name="pkg_childc",
+        )
 
         self._mock_modules = {
             "root": self.root_plugin,
diff --git a/tests/unit/test_manifest.py b/tests/unit/test_manifest.py
--- a/tests/unit/test_manifest.py
+++ b/tests/unit/test_manifest.py
@@ -1246,25 +1246,24 @@ def test_find_generate_macros_by_name(macros, expectations):
 
 def _materialization_parameter_sets():
     # inject the plugins used for materialization parameter tests
-    with mock.patch("dbt.adapters.base.plugin.project_name_from_path") as get_name:
-        get_name.return_value = "foo"
-        FooPlugin = AdapterPlugin(
-            adapter=mock.MagicMock(),
-            credentials=mock.MagicMock(),
-            include_path="/path/to/root/plugin",
-        )
-        FooPlugin.adapter.type.return_value = "foo"
-        inject_plugin(FooPlugin)
-
-        get_name.return_value = "bar"
-        BarPlugin = AdapterPlugin(
-            adapter=mock.MagicMock(),
-            credentials=mock.MagicMock(),
-            include_path="/path/to/root/plugin",
-            dependencies=["foo"],
-        )
-        BarPlugin.adapter.type.return_value = "bar"
-        inject_plugin(BarPlugin)
+    FooPlugin = AdapterPlugin(
+        adapter=mock.MagicMock(),
+        credentials=mock.MagicMock(),
+        include_path="/path/to/root/plugin",
+        project_name="foo",
+    )
+    FooPlugin.adapter.type.return_value = "foo"
+    inject_plugin(FooPlugin)
+
+    BarPlugin = AdapterPlugin(
+        adapter=mock.MagicMock(),
+        credentials=mock.MagicMock(),
+        include_path="/path/to/root/plugin",
+        dependencies=["foo"],
+        project_name="bar",
+    )
+    BarPlugin.adapter.type.return_value = "bar"
+    inject_plugin(BarPlugin)
 
     sets = [
         FindMaterializationSpec(macros=[], adapter_type="foo", expected=None),