Skip to content

Commit

Permalink
add latest_version attribute to ModelNode, is_latest_version as property
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Apr 12, 2023
1 parent bb79e71 commit 6e49ea5
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def add_node(self, node: ManifestNode):
if node.search_name not in self.storage:
self.storage[node.search_name] = {}
self.storage[node.search_name][node.package_name] = node.unique_id
if node.is_latest_version:
if node.is_latest_version: # type: ignore
self.storage[node.name][node.package_name] = node.unique_id
else:
self.storage[node.name][node.package_name] = node.unique_id
Expand Down
16 changes: 10 additions & 6 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def patch(self, patch: "ParsedNodePatch"):
self.columns = patch.columns
self.name = patch.name

# TODO: version, is_latest_version, and access are specific to ModelNodes, consider splitting out to ModelNode
# TODO: version, latest_version, and access are specific to ModelNodes, consider splitting out to ModelNode
if self.resource_type != NodeType.Model:
if patch.version:
warn_or_error(
Expand All @@ -453,16 +453,16 @@ def patch(self, patch: "ParsedNodePatch"):
node_name=patch.name,
)
)
if patch.is_latest_version:
if patch.latest_version:
warn_or_error(
ValidationWarning(
field_name="is_latest_version",
field_name="latest_version",
resource_type=self.resource_type.value,
node_name=patch.name,
)
)
self.version = patch.version
self.is_latest_version = patch.is_latest_version
self.latest_version = patch.latest_version

# This might not be the ideal place to validate the "access" field,
# but at this point we have the information we need to properly
Expand Down Expand Up @@ -631,7 +631,11 @@ class ModelNode(CompiledNode):
access: AccessType = AccessType.Protected
constraints: List[ModelLevelConstraint] = field(default_factory=list)
version: Optional[NodeVersion] = None
is_latest_version: Optional[bool] = None
latest_version: Optional[NodeVersion] = None

@property
def is_latest_version(self):
return self.version and self.version == self.latest_version

@property
def search_name(self):
Expand Down Expand Up @@ -1317,7 +1321,7 @@ class ParsedNodePatch(ParsedPatch):
columns: Dict[str, ColumnInfo]
access: Optional[str]
version: Optional[NodeVersion]
is_latest_version: Optional[bool]
latest_version: Optional[NodeVersion]


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def parse_patch(self, block: TargetBlock[NodeTarget], refs: ParserRef) -> None:
config=block.target.config,
access=block.target.access,
version=None,
is_latest_version=None,
latest_version=None,
)
assert isinstance(self.yaml.file, SchemaSourceFile)
source_file: SchemaSourceFile = self.yaml.file
Expand Down Expand Up @@ -1150,7 +1150,7 @@ def parse_patch(self, block: TargetBlock[UnparsedModelUpdate], refs: ParserRef)
config=deep_merge(target.config, unparsed_version.config),
access=unparsed_version.access or target.access,
version=unparsed_version.v,
is_latest_version=latest_version == unparsed_version.v,
latest_version=latest_version,
)
# Node patched before config because config patching depends on model name,
# which may have been updated in the version patch
Expand Down
43 changes: 23 additions & 20 deletions schemas/dbt/manifest/v9.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
"generated_at": {
"type": "string",
"format": "date-time",
"default": "2023-04-11T19:52:19.583214Z"
"default": "2023-04-12T03:35:01.188035Z"
},
"invocation_id": {
"oneOf": [
Expand All @@ -232,7 +232,7 @@
"type": "null"
}
],
"default": "c7e00436-b3f5-482c-b5e7-4ffa51478509"
"default": "8aa1596d-f52f-40bc-ad4b-f5e48fc7e6c2"
},
"env": {
"type": "object",
Expand Down Expand Up @@ -451,7 +451,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.584841
"default": 1681270501.189703
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1155,7 +1155,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.586099
"default": 1681270501.19095
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1542,7 +1542,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.586685
"default": 1681270501.191555
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1817,7 +1817,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.587269
"default": 1681270501.192162
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1946,10 +1946,13 @@
}
]
},
"is_latest_version": {
"latest_version": {
"oneOf": [
{
"type": "boolean"
"type": "string"
},
{
"type": "number"
},
{
"type": "null"
Expand All @@ -1958,7 +1961,7 @@
}
},
"additionalProperties": false,
"description": "ModelNode(database: Optional[str], schema: str, name: str, resource_type: dbt.node_types.NodeType, package_name: str, path: str, original_file_path: str, unique_id: str, fqn: List[str], alias: str, checksum: dbt.contracts.files.FileHash, config: dbt.contracts.graph.model_config.NodeConfig = <factory>, _event_status: Dict[str, Any] = <factory>, tags: List[str] = <factory>, description: str = '', columns: Dict[str, dbt.contracts.graph.nodes.ColumnInfo] = <factory>, meta: Dict[str, Any] = <factory>, group: Optional[str] = None, docs: dbt.contracts.graph.unparsed.Docs = <factory>, patch_path: Optional[str] = None, build_path: Optional[str] = None, deferred: bool = False, unrendered_config: Dict[str, Any] = <factory>, created_at: float = <factory>, config_call_dict: Dict[str, Any] = <factory>, relation_name: Optional[str] = None, raw_code: str = '', language: str = 'sql', refs: List[dbt.contracts.graph.nodes.RefArgs] = <factory>, sources: List[List[str]] = <factory>, metrics: List[List[str]] = <factory>, depends_on: dbt.contracts.graph.nodes.DependsOn = <factory>, compiled_path: Optional[str] = None, compiled: bool = False, compiled_code: Optional[str] = None, extra_ctes_injected: bool = False, extra_ctes: List[dbt.contracts.graph.nodes.InjectedCTE] = <factory>, _pre_injected_sql: Optional[str] = None, contract: dbt.contracts.graph.nodes.Contract = <factory>, access: dbt.node_types.AccessType = <AccessType.Protected: 'protected'>, constraints: List[dbt.contracts.graph.nodes.ModelLevelConstraint] = <factory>, version: Union[str, float, NoneType] = None, is_latest_version: Optional[bool] = None)"
"description": "ModelNode(database: Optional[str], schema: str, name: str, resource_type: dbt.node_types.NodeType, package_name: str, path: str, original_file_path: str, unique_id: str, fqn: List[str], alias: str, checksum: dbt.contracts.files.FileHash, config: dbt.contracts.graph.model_config.NodeConfig = <factory>, _event_status: Dict[str, Any] = <factory>, tags: List[str] = <factory>, description: str = '', columns: Dict[str, dbt.contracts.graph.nodes.ColumnInfo] = <factory>, meta: Dict[str, Any] = <factory>, group: Optional[str] = None, docs: dbt.contracts.graph.unparsed.Docs = <factory>, patch_path: Optional[str] = None, build_path: Optional[str] = None, deferred: bool = False, unrendered_config: Dict[str, Any] = <factory>, created_at: float = <factory>, config_call_dict: Dict[str, Any] = <factory>, relation_name: Optional[str] = None, raw_code: str = '', language: str = 'sql', refs: List[dbt.contracts.graph.nodes.RefArgs] = <factory>, sources: List[List[str]] = <factory>, metrics: List[List[str]] = <factory>, depends_on: dbt.contracts.graph.nodes.DependsOn = <factory>, compiled_path: Optional[str] = None, compiled: bool = False, compiled_code: Optional[str] = None, extra_ctes_injected: bool = False, extra_ctes: List[dbt.contracts.graph.nodes.InjectedCTE] = <factory>, _pre_injected_sql: Optional[str] = None, contract: dbt.contracts.graph.nodes.Contract = <factory>, access: dbt.node_types.AccessType = <AccessType.Protected: 'protected'>, constraints: List[dbt.contracts.graph.nodes.ModelLevelConstraint] = <factory>, version: Union[str, float, NoneType] = None, latest_version: Union[str, float, NoneType] = None)"
},
"ModelLevelConstraint": {
"type": "object",
Expand Down Expand Up @@ -2177,7 +2180,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.58805
"default": 1681270501.192949
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -2442,7 +2445,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.588607
"default": 1681270501.1935291
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -2700,7 +2703,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.5892649
"default": 1681270501.19419
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -2995,7 +2998,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.590366
"default": 1681270501.1952698
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -3482,7 +3485,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.591352
"default": 1681270501.1968079
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -3884,7 +3887,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.59236
"default": 1681270501.197819
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -3999,7 +4002,7 @@
"generated_at": {
"type": "string",
"format": "date-time",
"default": "2023-04-11T19:52:19.581122Z"
"default": "2023-04-12T03:35:01.185979Z"
},
"invocation_id": {
"oneOf": [
Expand All @@ -4010,7 +4013,7 @@
"type": "null"
}
],
"default": "c7e00436-b3f5-482c-b5e7-4ffa51478509"
"default": "8aa1596d-f52f-40bc-ad4b-f5e48fc7e6c2"
},
"env": {
"type": "object",
Expand Down Expand Up @@ -4363,7 +4366,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.5926442
"default": 1681270501.198105
},
"supported_languages": {
"oneOf": [
Expand Down Expand Up @@ -4603,7 +4606,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.593288
"default": 1681270501.198782
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -4823,7 +4826,7 @@
},
"created_at": {
"type": "number",
"default": 1681242739.5939379
"default": 1681270501.199492
},
"group": {
"oneOf": [
Expand Down
10 changes: 5 additions & 5 deletions test/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def basic_parsed_model_patch_dict():
"config": {},
"access": "public",
"version": "1",
"is_latest_version": True,
"latest_version": "1",
}


Expand All @@ -802,7 +802,7 @@ def basic_parsed_model_patch_object():
config={},
access="public",
version="1",
is_latest_version=True,
latest_version="1",
)


Expand Down Expand Up @@ -836,7 +836,7 @@ def patched_model_object():
unrendered_config={},
access=AccessType.Public,
version="1",
is_latest_version=True,
latest_version="1",
)


Expand Down Expand Up @@ -1920,7 +1920,7 @@ def populated_parsed_node_patch_dict():
"config": {},
"access": "public",
"version": "1",
"is_latest_version": True,
"latest_version": "1",
}


Expand All @@ -1938,7 +1938,7 @@ def populated_parsed_node_patch_object():
config={},
access="public",
version="1",
is_latest_version=True,
latest_version="1",
)


Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def make_model(
fqn_extras=None,
depends_on_macros=None,
version=None,
is_latest_version=None,
latest_version=None,
):
if refs is None:
refs = []
Expand Down Expand Up @@ -118,7 +118,7 @@ def make_model(
resource_type=NodeType.Model,
checksum=FileHash.from_contents(""),
version=version,
is_latest_version=is_latest_version,
latest_version=latest_version,
)


Expand Down Expand Up @@ -608,7 +608,7 @@ def versioned_model_v1(seed):
sources=[],
path="subdirectory/versioned_model_v1.sql",
version=1,
is_latest_version=True,
latest_version=1,
)


Expand All @@ -623,7 +623,7 @@ def versioned_model_v2(seed):
sources=[],
path="subdirectory/versioned_model_v2.sql",
version=2,
is_latest_version=False,
latest_version=1,
)


Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"contract",
"access",
"version",
"is_latest_version",
"latest_version",
"constraints",
}
)
Expand Down
Loading

0 comments on commit 6e49ea5

Please sign in to comment.