Repository: dbt-labs/dbt-core

Issue:
[CT-3502] remove dependency on RuntimeConfigObject



Discussion:

Resolving patch:
diff --git a/plugins/postgres/dbt/adapters/postgres/impl.py b/plugins/postgres/dbt/adapters/postgres/impl.py
--- a/plugins/postgres/dbt/adapters/postgres/impl.py
+++ b/plugins/postgres/dbt/adapters/postgres/impl.py
@@ -18,7 +18,7 @@
     IndexConfigError,
     UnexpectedDbReferenceError,
 )
-import dbt.utils
+from dbt.common.utils import encoding as dbt_encoding
 
 
 GET_RELATIONS_MACRO_NAME = "postgres__get_relations"
@@ -38,7 +38,7 @@ def render(self, relation):
         now = datetime.utcnow().isoformat()
         inputs = self.columns + [relation.render(), str(self.unique), str(self.type), now]
         string = "_".join(inputs)
-        return dbt.utils.md5(string)
+        return dbt_encoding.md5(string)
 
     @classmethod
     def parse(cls, raw_index) -> Optional["PostgresIndexConfig"]:
diff --git a/plugins/postgres/dbt/adapters/postgres/relation.py b/plugins/postgres/dbt/adapters/postgres/relation.py
--- a/plugins/postgres/dbt/adapters/postgres/relation.py
+++ b/plugins/postgres/dbt/adapters/postgres/relation.py
@@ -6,8 +6,7 @@
     RelationConfigChangeAction,
     RelationResults,
 )
-from dbt.context.providers import RuntimeConfigObject
-from dbt.adapters.contracts.relation import RelationType
+from dbt.adapters.contracts.relation import RelationType, RelationConfig
 from dbt.common.exceptions import DbtRuntimeError
 
 from dbt.adapters.postgres.relation_configs import (
@@ -52,16 +51,14 @@ def relation_max_name_length(self):
         return MAX_CHARACTERS_IN_IDENTIFIER
 
     def get_materialized_view_config_change_collection(
-        self, relation_results: RelationResults, runtime_config: RuntimeConfigObject
+        self, relation_results: RelationResults, relation_config: RelationConfig
     ) -> Optional[PostgresMaterializedViewConfigChangeCollection]:
         config_change_collection = PostgresMaterializedViewConfigChangeCollection()
 
         existing_materialized_view = PostgresMaterializedViewConfig.from_relation_results(
             relation_results
         )
-        new_materialized_view = PostgresMaterializedViewConfig.from_model_node(
-            runtime_config.model
-        )
+        new_materialized_view = PostgresMaterializedViewConfig.from_config(relation_config)
 
         config_change_collection.indexes = self._get_index_config_changes(
             existing_materialized_view.indexes, new_materialized_view.indexes
diff --git a/plugins/postgres/dbt/adapters/postgres/relation_configs/materialized_view.py b/plugins/postgres/dbt/adapters/postgres/relation_configs/materialized_view.py
--- a/plugins/postgres/dbt/adapters/postgres/relation_configs/materialized_view.py
+++ b/plugins/postgres/dbt/adapters/postgres/relation_configs/materialized_view.py
@@ -1,5 +1,6 @@
 from dataclasses import dataclass, field
-from typing import Set, FrozenSet, List
+from typing import Set, FrozenSet, List, Dict
+from typing_extensions import Self
 
 import agate
 from dbt.adapters.relation_configs import (
@@ -8,7 +9,7 @@
     RelationConfigValidationMixin,
     RelationConfigValidationRule,
 )
-from dbt.contracts.graph.nodes import ModelNode
+from dbt.adapters.contracts.relation import RelationConfig
 from dbt.common.exceptions import DbtRuntimeError
 
 from dbt.adapters.postgres.relation_configs.constants import MAX_CHARACTERS_IN_IDENTIFIER
@@ -54,7 +55,7 @@ def validation_rules(self) -> Set[RelationConfigValidationRule]:
         }
 
     @classmethod
-    def from_dict(cls, config_dict: dict) -> "PostgresMaterializedViewConfig":
+    def from_dict(cls, config_dict: dict) -> Self:
         kwargs_dict = {
             "table_name": config_dict.get("table_name"),
             "query": config_dict.get("query"),
@@ -62,29 +63,27 @@ def from_dict(cls, config_dict: dict) -> "PostgresMaterializedViewConfig":
                 PostgresIndexConfig.from_dict(index) for index in config_dict.get("indexes", {})
             ),
         }
-        materialized_view: "PostgresMaterializedViewConfig" = super().from_dict(kwargs_dict)  # type: ignore
+        materialized_view: Self = super().from_dict(kwargs_dict)  # type: ignore
         return materialized_view
 
     @classmethod
-    def from_model_node(cls, model_node: ModelNode) -> "PostgresMaterializedViewConfig":
-        materialized_view_config = cls.parse_model_node(model_node)
+    def from_config(cls, relation_config: RelationConfig) -> Self:
+        materialized_view_config = cls.parse_config(relation_config)
         materialized_view = cls.from_dict(materialized_view_config)
         return materialized_view
 
     @classmethod
-    def parse_model_node(cls, model_node: ModelNode) -> dict:
-        indexes: List[dict] = model_node.config.extra.get("indexes", [])
+    def parse_config(cls, relation_config: RelationConfig) -> Dict:
+        indexes: List[dict] = relation_config.config.extra.get("indexes", [])
         config_dict = {
-            "table_name": model_node.identifier,
-            "query": model_node.compiled_code,
+            "table_name": relation_config.identifier,
+            "query": relation_config.compiled_code,
             "indexes": [PostgresIndexConfig.parse_model_node(index) for index in indexes],
         }
         return config_dict
 
     @classmethod
-    def from_relation_results(
-        cls, relation_results: RelationResults
-    ) -> "PostgresMaterializedViewConfig":
+    def from_relation_results(cls, relation_results: RelationResults) -> Self:
         materialized_view_config = cls.parse_relation_results(relation_results)
         materialized_view = cls.from_dict(materialized_view_config)
         return materialized_view


Test patch: