mirror of
https://github.com/dbt-labs/dbt-core
synced 2025-12-17 19:31:34 +00:00
Correct Function Node Property Names (#12065)
* Fix function node property names `return_type` -> `returns` `return_type.type` -> `returns.data_type` `arguments[x].type` -> `arguments[x].data_type` * Add changie doc
This commit is contained in:
6
.changes/unreleased/Fixes-20251002-121427.yaml
Normal file
6
.changes/unreleased/Fixes-20251002-121427.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
kind: Fixes
|
||||
body: Fix property names of function nodes (arguments.data_type, returns, returns.data_type)
|
||||
time: 2025-10-02T12:14:27.305546-05:00
|
||||
custom:
|
||||
Author: QMalcolm
|
||||
Issue: "12064"
|
||||
@@ -40,7 +40,7 @@ from dbt.artifacts.resources.v1.function import (
|
||||
FunctionArgument,
|
||||
FunctionConfig,
|
||||
FunctionMandatory,
|
||||
FunctionReturnType,
|
||||
FunctionReturns,
|
||||
)
|
||||
from dbt.artifacts.resources.v1.generic_test import GenericTest, TestMetadata
|
||||
from dbt.artifacts.resources.v1.group import Group, GroupConfig
|
||||
|
||||
@@ -26,19 +26,19 @@ class FunctionConfig(NodeConfig):
|
||||
@dataclass
|
||||
class FunctionArgument(dbtClassMixin):
|
||||
name: str
|
||||
type: str
|
||||
data_type: str
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class FunctionReturnType(dbtClassMixin):
|
||||
type: str
|
||||
class FunctionReturns(dbtClassMixin):
|
||||
data_type: str
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class FunctionMandatory(dbtClassMixin):
|
||||
return_type: FunctionReturnType
|
||||
returns: FunctionReturns
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -33,7 +33,7 @@ from dbt.artifacts.resources import Documentation as DocumentationResource
|
||||
from dbt.artifacts.resources import Exposure as ExposureResource
|
||||
from dbt.artifacts.resources import FileHash
|
||||
from dbt.artifacts.resources import Function as FunctionResource
|
||||
from dbt.artifacts.resources import FunctionArgument, FunctionReturnType
|
||||
from dbt.artifacts.resources import FunctionArgument, FunctionReturns
|
||||
from dbt.artifacts.resources import GenericTest as GenericTestResource
|
||||
from dbt.artifacts.resources import GraphResource
|
||||
from dbt.artifacts.resources import Group as GroupResource
|
||||
@@ -1725,7 +1725,7 @@ class ParsedNodePatch(ParsedPatch):
|
||||
|
||||
@dataclass
|
||||
class ParsedFunctionPatchRequired:
|
||||
return_type: FunctionReturnType
|
||||
returns: FunctionReturns
|
||||
|
||||
|
||||
# TODO: Maybe this shouldn't be a subclass of ParsedNodePatch, but ParsedPatch instead
|
||||
|
||||
@@ -16,7 +16,7 @@ from dbt.artifacts.resources import (
|
||||
ExternalTable,
|
||||
FreshnessThreshold,
|
||||
FunctionArgument,
|
||||
FunctionReturnType,
|
||||
FunctionReturns,
|
||||
MacroArgument,
|
||||
MaturityType,
|
||||
MeasureAggregationParameters,
|
||||
@@ -663,14 +663,12 @@ class UnparsedGroup(dbtClassMixin):
|
||||
|
||||
|
||||
@dataclass
|
||||
class UnparsedFunctionReturnType(dbtClassMixin):
|
||||
return_type: FunctionReturnType
|
||||
class UnparsedFunctionReturns(dbtClassMixin):
|
||||
returns: FunctionReturns
|
||||
|
||||
|
||||
@dataclass
|
||||
class UnparsedFunctionUpdate(
|
||||
HasConfig, HasColumnProps, HasYamlMetadata, UnparsedFunctionReturnType
|
||||
):
|
||||
class UnparsedFunctionUpdate(HasConfig, HasColumnProps, HasYamlMetadata, UnparsedFunctionReturns):
|
||||
access: Optional[str] = None
|
||||
arguments: List[FunctionArgument] = field(default_factory=list)
|
||||
type: FunctionType = FunctionType.Scalar
|
||||
|
||||
@@ -256,7 +256,7 @@ class ConfiguredParser(
|
||||
# but we don't get the return type until we patch the node with the yml definition
|
||||
# so we need to set it to a default value here.
|
||||
if self.resource_type == NodeType.Function:
|
||||
dct["return_type"] = {"type": "INVALID_TYPE"}
|
||||
dct["returns"] = {"data_type": "INVALID_TYPE"}
|
||||
|
||||
try:
|
||||
return self.parse_from_dict(dct, validate=True)
|
||||
|
||||
@@ -1291,7 +1291,7 @@ class FunctionPatchParser(NodePatchParser[UnparsedFunctionUpdate]):
|
||||
assert isinstance(node, FunctionNode)
|
||||
|
||||
node.arguments = patch.arguments
|
||||
node.return_type = patch.return_type
|
||||
node.returns = patch.returns
|
||||
node.type = patch.type
|
||||
|
||||
def _get_node_patch(self, block: TargetBlock[NodeTarget], refs: ParserRef) -> ParsedNodePatch:
|
||||
@@ -1315,7 +1315,7 @@ class FunctionPatchParser(NodePatchParser[UnparsedFunctionUpdate]):
|
||||
deprecation_date=None,
|
||||
time_spine=None,
|
||||
arguments=target.arguments,
|
||||
return_type=target.return_type,
|
||||
returns=target.returns,
|
||||
type=target.type,
|
||||
)
|
||||
|
||||
|
||||
@@ -8133,11 +8133,11 @@
|
||||
"type": "object",
|
||||
"title": "Function",
|
||||
"properties": {
|
||||
"return_type": {
|
||||
"returns": {
|
||||
"type": "object",
|
||||
"title": "FunctionReturnType",
|
||||
"title": "FunctionReturns",
|
||||
"properties": {
|
||||
"type": {
|
||||
"data_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
@@ -8154,7 +8154,7 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"type"
|
||||
"data_type"
|
||||
]
|
||||
},
|
||||
"database": {
|
||||
@@ -8986,7 +8986,7 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"data_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
@@ -9004,7 +9004,7 @@
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"name",
|
||||
"type"
|
||||
"data_type"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -9019,7 +9019,7 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"return_type",
|
||||
"returns",
|
||||
"database",
|
||||
"schema",
|
||||
"name",
|
||||
@@ -19731,11 +19731,11 @@
|
||||
"type": "object",
|
||||
"title": "Function",
|
||||
"properties": {
|
||||
"return_type": {
|
||||
"returns": {
|
||||
"type": "object",
|
||||
"title": "FunctionReturnType",
|
||||
"title": "FunctionReturns",
|
||||
"properties": {
|
||||
"type": {
|
||||
"data_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
@@ -19752,7 +19752,7 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"type"
|
||||
"data_type"
|
||||
]
|
||||
},
|
||||
"database": {
|
||||
@@ -20584,7 +20584,7 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"data_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
@@ -20602,7 +20602,7 @@
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"name",
|
||||
"type"
|
||||
"data_type"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -20617,7 +20617,7 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"return_type",
|
||||
"returns",
|
||||
"database",
|
||||
"schema",
|
||||
"name",
|
||||
@@ -26249,11 +26249,11 @@
|
||||
"type": "object",
|
||||
"title": "Function",
|
||||
"properties": {
|
||||
"return_type": {
|
||||
"returns": {
|
||||
"type": "object",
|
||||
"title": "FunctionReturnType",
|
||||
"title": "FunctionReturns",
|
||||
"properties": {
|
||||
"type": {
|
||||
"data_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
@@ -26270,7 +26270,7 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"type"
|
||||
"data_type"
|
||||
]
|
||||
},
|
||||
"database": {
|
||||
@@ -27102,7 +27102,7 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"data_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
@@ -27120,7 +27120,7 @@
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"name",
|
||||
"type"
|
||||
"data_type"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -27135,7 +27135,7 @@
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"return_type",
|
||||
"returns",
|
||||
"database",
|
||||
"schema",
|
||||
"name",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -412,7 +412,7 @@ class TestPreviousVersionState:
|
||||
current_manifest_schema_version == self.CURRENT_EXPECTED_MANIFEST_VERSION
|
||||
), "Sounds like you've bumped the manifest version and need to update this test!"
|
||||
# If we need a newly generated manifest, uncomment the following line and commit the result
|
||||
# self.generate_latest_manifest(project, current_manifest_schema_version)
|
||||
self.generate_latest_manifest(project, current_manifest_schema_version)
|
||||
self.compare_previous_state(project, current_manifest_schema_version, True, 0)
|
||||
|
||||
def test_backwards_compatible_versions(self, project):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@ functions:
|
||||
description: Calculates the area of a circle for a given radius
|
||||
arguments:
|
||||
- name: radius
|
||||
type: float
|
||||
data_type: float
|
||||
description: A floating point number representing the radius of the circle
|
||||
return_type:
|
||||
type: float
|
||||
returns:
|
||||
data_type: float
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import Dict
|
||||
|
||||
import pytest
|
||||
|
||||
from dbt.artifacts.resources import FunctionReturnType
|
||||
from dbt.artifacts.resources import FunctionReturns
|
||||
from dbt.artifacts.resources.types import FunctionType
|
||||
from dbt.contracts.graph.nodes import FunctionNode
|
||||
from dbt.tests.util import run_dbt
|
||||
@@ -18,10 +18,10 @@ functions:
|
||||
description: Sums the sequence of numbers and then doubles the result
|
||||
arguments:
|
||||
- name: values
|
||||
type: float
|
||||
data_type: float
|
||||
description: A sequence of numbers
|
||||
return_type:
|
||||
type: float
|
||||
returns:
|
||||
data_type: float
|
||||
"""
|
||||
|
||||
|
||||
@@ -48,6 +48,6 @@ class TestBasicSQLUDAF(BasicUDAFSetup):
|
||||
assert len(function_node.arguments) == 1
|
||||
argument = function_node.arguments[0]
|
||||
assert argument.name == "values"
|
||||
assert argument.type == "float"
|
||||
assert argument.data_type == "float"
|
||||
assert argument.description == "A sequence of numbers"
|
||||
assert function_node.return_type == FunctionReturnType(type="float")
|
||||
assert function_node.returns == FunctionReturns(data_type="float")
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import Dict
|
||||
import agate
|
||||
import pytest
|
||||
|
||||
from dbt.artifacts.resources import FunctionReturnType
|
||||
from dbt.artifacts.resources import FunctionReturns
|
||||
from dbt.artifacts.resources.types import FunctionType
|
||||
from dbt.contracts.graph.nodes import FunctionNode
|
||||
from dbt.tests.util import run_dbt
|
||||
@@ -18,10 +18,10 @@ functions:
|
||||
description: Doubles whatever number is passed in
|
||||
arguments:
|
||||
- name: value
|
||||
type: float
|
||||
data_type: float
|
||||
description: A number to be doubled
|
||||
return_type:
|
||||
type: float
|
||||
returns:
|
||||
data_type: float
|
||||
"""
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ class TestBasicSQLUDF(BasicUDFSetup):
|
||||
assert len(function_node.arguments) == 1
|
||||
argument = function_node.arguments[0]
|
||||
assert argument.name == "value"
|
||||
assert argument.type == "float"
|
||||
assert argument.data_type == "float"
|
||||
assert argument.description == "A number to be doubled"
|
||||
assert function_node.return_type == FunctionReturnType(type="float")
|
||||
assert function_node.returns == FunctionReturns(data_type="float")
|
||||
|
||||
|
||||
class TestCreationOfUDFs(BasicUDFSetup):
|
||||
@@ -64,7 +64,7 @@ class TestCreationOfUDFs(BasicUDFSetup):
|
||||
argument = function_node.arguments[0]
|
||||
assert argument.name == "value"
|
||||
assert argument.type == "float"
|
||||
assert results[0].node.return_type == FunctionReturnType(type="float")
|
||||
assert results[0].node.returns == FunctionReturns(type="float")
|
||||
|
||||
|
||||
class TestCanInlineShowUDF(BasicUDFSetup):
|
||||
|
||||
Reference in New Issue
Block a user