Skip to content

Commit

Permalink
Merge branch 'cl/allow_additional_property_for_model_and_source' of h…
Browse files Browse the repository at this point in the history
…ttps://github.com/dbt-labs/dbt-core into cl/allow_additional_property_for_model_and_source
  • Loading branch information
ChenyuLInx committed Dec 12, 2024
2 parents 7df04b0 + 13acd66 commit 5b36ec7
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 41 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20241211-160216.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Allow additional property on Model and SourceDefinition to avoid artifact read
problem
time: 2024-12-11T16:02:16.551106-08:00
custom:
Author: ChenyuLInx
Issue: 8797 11123
3 changes: 2 additions & 1 deletion core/dbt/artifacts/resources/v1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from dbt.artifacts.resources.v1.config import NodeConfig
from dbt_common.contracts.config.base import MergeBehavior
from dbt_common.contracts.config.properties import AdditionalPropertiesAllowed
from dbt_common.contracts.constraints import ModelLevelConstraint
from dbt_common.dataclass_schema import dbtClassMixin

Expand All @@ -35,7 +36,7 @@ class TimeSpine(dbtClassMixin):


@dataclass
class Model(CompiledResource):
class Model(AdditionalPropertiesAllowed, CompiledResource):
resource_type: Literal[NodeType.Model]
access: AccessType = AccessType.Protected
config: ModelConfig = field(default_factory=ModelConfig)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/artifacts/resources/v1/source_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ParsedSourceMandatory(GraphResource, HasRelationMetadata):


@dataclass
class SourceDefinition(ParsedSourceMandatory):
class SourceDefinition(AdditionalPropertiesAllowed, ParsedSourceMandatory):
quoting: Quoting = field(default_factory=Quoting)
loaded_at_field: Optional[str] = None
freshness: Optional[FreshnessThreshold] = None
Expand Down
8 changes: 8 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ def __post_serialize__(self, dct: Dict, context: Optional[Dict] = None):
del dct["_has_this"]
if "previous_batch_results" in dct:
del dct["previous_batch_results"]
if "batch" in dct:
del dct["batch"]
return dct

@classmethod
Expand Down Expand Up @@ -1371,6 +1373,12 @@ def search_name(self):
def group(self):
return None

def __post_serialize__(self, dct: Dict, context: Optional[Dict] = None):
dct = super().__post_serialize__(dct, context)
if "_event_status" in dct:
del dct["_event_status"]
return dct


# ====================================
# Exposure node
Expand Down
188 changes: 157 additions & 31 deletions schemas/dbt/manifest/v12.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dbt_version": {
"type": "string",
"default": "1.9.0b4"
"default": "1.10.0a1"
},
"generated_at": {
"type": "string"
Expand Down Expand Up @@ -4205,6 +4205,12 @@
},
"additionalProperties": false
},
"_extra": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"access": {
"enum": [
"private",
Expand Down Expand Up @@ -4779,7 +4785,7 @@
"default": null
}
},
"additionalProperties": false,
"additionalProperties": true,
"required": [
"database",
"schema",
Expand Down Expand Up @@ -7690,6 +7696,12 @@
"identifier": {
"type": "string"
},
"_extra": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"quoting": {
"type": "object",
"title": "Quoting",
Expand Down Expand Up @@ -8223,7 +8235,7 @@
"default": null
}
},
"additionalProperties": false,
"additionalProperties": true,
"required": [
"database",
"schema",
Expand Down Expand Up @@ -9121,19 +9133,7 @@
"type": "integer"
},
"granularity": {
"enum": [
"nanosecond",
"microsecond",
"millisecond",
"second",
"minute",
"hour",
"day",
"week",
"month",
"quarter",
"year"
]
"type": "string"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -14014,6 +14014,12 @@
},
"additionalProperties": false
},
"_extra": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"access": {
"enum": [
"private",
Expand Down Expand Up @@ -14588,7 +14594,7 @@
"default": null
}
},
"additionalProperties": false,
"additionalProperties": true,
"required": [
"database",
"schema",
Expand Down Expand Up @@ -17490,6 +17496,12 @@
"identifier": {
"type": "string"
},
"_extra": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"quoting": {
"type": "object",
"title": "Quoting",
Expand Down Expand Up @@ -18023,7 +18035,7 @@
"default": null
}
},
"additionalProperties": false,
"additionalProperties": true,
"required": [
"database",
"schema",
Expand Down Expand Up @@ -18712,19 +18724,7 @@
"type": "integer"
},
"granularity": {
"enum": [
"nanosecond",
"microsecond",
"millisecond",
"second",
"minute",
"hour",
"day",
"week",
"month",
"quarter",
"year"
]
"type": "string"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -20024,6 +20024,27 @@
}
],
"default": null
},
"config": {
"anyOf": [
{
"type": "object",
"title": "SemanticLayerElementConfig",
"properties": {
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": false
},
{
"type": "null"
}
],
"default": null
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -20178,6 +20199,27 @@
}
],
"default": null
},
"config": {
"anyOf": [
{
"type": "object",
"title": "SemanticLayerElementConfig",
"properties": {
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": false
},
{
"type": "null"
}
],
"default": null
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -20341,6 +20383,27 @@
}
],
"default": null
},
"config": {
"anyOf": [
{
"type": "object",
"title": "SemanticLayerElementConfig",
"properties": {
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": false
},
{
"type": "null"
}
],
"default": null
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -21586,6 +21649,27 @@
}
],
"default": null
},
"config": {
"anyOf": [
{
"type": "object",
"title": "SemanticLayerElementConfig",
"properties": {
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": false
},
{
"type": "null"
}
],
"default": null
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -21740,6 +21824,27 @@
}
],
"default": null
},
"config": {
"anyOf": [
{
"type": "object",
"title": "SemanticLayerElementConfig",
"properties": {
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": false
},
{
"type": "null"
}
],
"default": null
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -21903,6 +22008,27 @@
}
],
"default": null
},
"config": {
"anyOf": [
{
"type": "object",
"title": "SemanticLayerElementConfig",
"properties": {
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": false
},
{
"type": "null"
}
],
"default": null
}
},
"additionalProperties": false,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/contracts/graph/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"deprecation_date",
"defer_relation",
"time_spine",
"batch",
}
)

Expand Down
9 changes: 5 additions & 4 deletions tests/unit/contracts/graph/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ def test_basic_compiled_model(basic_compiled_dict, basic_compiled_model):
assert node.is_ephemeral is False


def test_invalid_extra_fields_model(minimal_uncompiled_dict):
bad_extra = minimal_uncompiled_dict
bad_extra["notvalid"] = "nope"
assert_fails_validation(bad_extra, ModelNode)
def test_extra_fields_model_okay(minimal_uncompiled_dict):
extra = minimal_uncompiled_dict
extra["notvalid"] = "nope"
# Model still load fine with extra fields
assert ModelNode.from_dict(extra)._extra == {"notvalid": "nope"}


def test_invalid_bad_type_model(minimal_uncompiled_dict):
Expand Down
Loading

0 comments on commit 5b36ec7

Please sign in to comment.