Skip to content

Commit

Permalink
Merge branch 'main' into 6014-use_select_in_docs_generate
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Oct 4, 2023
2 parents 0da5b1a + c6ff3ab commit 5f85b19
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230929-170945.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Add meta attribute to SemanticModels config
time: 2023-09-29T17:09:45.0354-05:00
custom:
Author: emmyoop
Issue: "8511"
4 changes: 4 additions & 0 deletions core/dbt/contracts/graph/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ class SemanticModelConfig(BaseConfig):
default=None,
metadata=CompareBehavior.Exclude.meta(),
)
meta: Dict[str, Any] = field(
default_factory=dict,
metadata=MergeBehavior.Update.meta(),
)


@dataclass
Expand Down
1 change: 1 addition & 0 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def _generate_semantic_model_config(
base=False,
patch_config_dict=precedence_configs,
)

return config

def parse_semantic_model(self, unparsed: UnparsedSemanticModel):
Expand Down
6 changes: 6 additions & 0 deletions schemas/dbt/manifest/v11.json
Original file line number Diff line number Diff line change
Expand Up @@ -5497,6 +5497,12 @@
}
],
"default": null
},
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": true
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/semantic_models/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
config:
enabled: true
group: some_group
meta:
my_meta: 'testing'
my_other_meta: 'testing more'
dimensions:
- name: favorite_color
type: categorical
Expand Down Expand Up @@ -185,6 +188,7 @@
agg_time_dimension: created_at
"""


schema_yml = """models:
- name: fct_revenue
description: This is the model fct_revenue. It should be able to use doc blocks
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/semantic_models/test_semantic_model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,25 @@ def test_project_plus_yaml_level(self, project):
).config

assert isinstance(config_test_table, SemanticModelConfig)


# test setting meta attributes in semantic model config
class TestMetaConfig:
@pytest.fixture(scope="class")
def models(self):
return {
"people.sql": models_people_sql,
"metricflow_time_spine.sql": metricflow_time_spine_sql,
"semantic_models.yml": enabled_semantic_model_people_yml,
"people_metrics.yml": models_people_metrics_yml,
"groups.yml": groups_yml,
}

def test_meta_config(self, project):
run_dbt(["parse"])
manifest = get_manifest(project.project_root)
sm_id = "semantic_model.test.semantic_people"
assert sm_id in manifest.semantic_models
sm_node = manifest.semantic_models[sm_id]
meta_expected = {"my_meta": "testing", "my_other_meta": "testing more"}
assert sm_node.config.meta == meta_expected

0 comments on commit 5f85b19

Please sign in to comment.