Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow column description to be overwritten #291

Merged
merged 8 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions dbtmetabase/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
_COMMON_META_FIELDS = [
"display_name",
"visibility_type",
"description",
]
# Must be covered by Column attributes
_COLUMN_META_FIELDS = _COMMON_META_FIELDS + [
Expand Down Expand Up @@ -110,6 +111,12 @@ def _read_model(
for column in manifest_model.get("columns", {}).values()
]

meta = self._scan_fields(
manifest_model.get("meta", {}),
fields=_MODEL_META_FIELDS,
ns=_META_NS,
)
description = meta.pop("description", manifest_model.get("description"))
return Model(
database=database,
schema=schema,
Expand All @@ -118,16 +125,12 @@ def _read_model(
alias=manifest_model.get(
"alias", manifest_model.get("identifier", manifest_model["name"])
),
description=manifest_model.get("description"),
description=description,
columns=columns,
unique_id=unique_id,
source=source,
tags=manifest_model.get("tags", []),
**self._scan_fields(
manifest_model.get("meta", {}),
fields=_MODEL_META_FIELDS,
ns=_META_NS,
),
**meta,
)

def _read_column(
Expand All @@ -136,14 +139,16 @@ def _read_column(
schema: str,
relationship: Optional[Mapping],
) -> Column:
meta = self._scan_fields(
manifest_column.get("meta", {}),
fields=_COLUMN_META_FIELDS,
ns=_META_NS,
)
description = meta.get("description", manifest_column.get("description"))
column = Column(
name=manifest_column.get("name", ""),
description=manifest_column.get("description"),
**self._scan_fields(
manifest_column.get("meta", {}),
fields=_COLUMN_META_FIELDS,
ns=_META_NS,
),
description=description,
**meta,
)

self._set_column_relationship(
Expand Down
8 changes: 6 additions & 2 deletions tests/fixtures/manifest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@
"status": {
"name": "status",
"description": "Orders can be one of the following statuses:\n\n| status | description |\n|----------------|------------------------------------------------------------------------------------------------------------------------|\n| placed | The order has been placed but has not yet left the warehouse |\n| shipped | The order has ben shipped to the customer and is currently in transit |\n| completed | The order has been received by the customer |\n| return_pending | The customer has indicated that they would like to return the order, but it has not yet been received at the warehouse |\n| returned | The order has been returned by the customer and received at the warehouse |",
"meta": {},
"meta": {
"metabase.description": "Order status: placed, shipped, completed, return_pending, or returned."
},
"data_type": null,
"quote": null,
"tags": []
Expand Down Expand Up @@ -145,7 +147,9 @@
"tags": []
}
},
"meta": {},
"meta": {
"metabase.description": "Basic and derived order information from payments"
},
"docs": {
"show": true
},
Expand Down
4 changes: 2 additions & 2 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_v2():
group=Group.nodes,
name="orders",
alias="orders",
description="This table has basic information about orders, as well as some derived facts based on payments",
description="Basic and derived order information from payments",
unique_id="model.jaffle_shop.orders",
columns=[
Column(
Expand All @@ -278,7 +278,7 @@ def test_v2():
),
Column(
name="status",
description="Orders can be one of the following statuses:\n\n| status | description |\n|----------------|------------------------------------------------------------------------------------------------------------------------|\n| placed | The order has been placed but has not yet left the warehouse |\n| shipped | The order has ben shipped to the customer and is currently in transit |\n| completed | The order has been received by the customer |\n| return_pending | The customer has indicated that they would like to return the order, but it has not yet been received at the warehouse |\n| returned | The order has been returned by the customer and received at the warehouse |",
description="Order status: placed, shipped, completed, return_pending, or returned.",
),
Column(
name="amount",
Expand Down
Loading