Skip to content

Commit

Permalink
fix: Add validator on ManifestNode.resource_type to detect and fix mi…
Browse files Browse the repository at this point in the history
…smatched node/resource types
  • Loading branch information
nicholasyager committed Aug 30, 2024
1 parent b00e79f commit a38279b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions dbt_loom/manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class ManifestNode(BaseModel):
"""A basic ManifestNode that can be referenced across projects."""

name: str
resource_type: NodeType
package_name: str
unique_id: str
resource_type: NodeType
schema_name: str = Field(alias="schema")
database: Optional[str] = None
relation_name: Optional[str] = None
Expand All @@ -58,6 +59,14 @@ def default_depends_on_nodes(cls, v, values):
node for node in depends_on.nodes if node.split(".")[0] not in ("source")
]

@validator("resource_type", always=True)
def fix_resource_types(cls, v, values):
"""If the resource type does not match the unique_id prefix, then rewrite the resource type."""

node_type = values.get("unique_id").split(".")[0]
if v != node_type:
return node_type

@property
def identifier(self) -> str:
if not self.relation_name:
Expand All @@ -81,9 +90,9 @@ def load_from_local_filesystem(config: FileReferenceConfig) -> Dict:
"""Load a manifest dictionary from a local file"""
if not config.path.exists():
raise LoomConfigurationError(f"The path `{config.path}` does not exist.")
if config.path.suffix == '.gz':
with gzip.open(config.path, 'rt') as file:

if config.path.suffix == ".gz":
with gzip.open(config.path, "rt") as file:
return json.load(file)
else:
return json.load(open(config.path))
Expand Down

0 comments on commit a38279b

Please sign in to comment.