Skip to content

Commit

Permalink
feat: allow unknown owner (preset-io#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrodingers committed Apr 24, 2023
1 parent 858f0d3 commit 381cd47
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/preset_cli/cli/superset/sync/dbt/exposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def get_dashboard_depends_on(
Get all the dbt dependencies for a given dashboard.
"""

url = client.baseurl / "api/v1/dashboard" / str(dashboard["id"]) / "datasets"
url = client.baseurl / "api/v1/dashboard" / \
str(dashboard["id"]) / "datasets"

session = client.auth.session
headers = client.auth.get_headers()
Expand Down Expand Up @@ -96,7 +97,8 @@ def sync_exposures( # pylint: disable=too-many-locals
dashboards_ids = set()

for dataset in datasets:
url = client.baseurl / "api/v1/dataset" / str(dataset["id"]) / "related_objects"
url = client.baseurl / "api/v1/dataset" / \
str(dataset["id"]) / "related_objects"

session = client.auth.session
headers = client.auth.get_headers()
Expand All @@ -111,7 +113,8 @@ def sync_exposures( # pylint: disable=too-many-locals

for chart_id in charts_ids:
chart = client.get_chart(chart_id)
first_owner = chart["owners"][0]
first_owner = chart["owners"][0] if len(chart["owners"]) else {
"first_name": "Unknown", "last_name": "Owner"}
exposure = {
"name": chart["slice_name"] + " [chart]",
"type": "analysis",
Expand All @@ -122,7 +125,7 @@ def sync_exposures( # pylint: disable=too-many-locals
% {"form_data": json.dumps({"slice_id": chart_id})},
),
"description": chart["description"] or "",
"meta": { "id": chart_id },
"meta": {"id": chart_id},
"depends_on": get_chart_depends_on(client, chart, model_map),
"owner": {
"name": first_owner["first_name"] + " " + first_owner["last_name"],
Expand All @@ -133,7 +136,8 @@ def sync_exposures( # pylint: disable=too-many-locals

for dashboard_id in dashboards_ids:
dashboard = client.get_dashboard(dashboard_id)
first_owner = dashboard["owners"][0]
first_owner = dashboard["owners"][0] if len(dashboard["owners"]) else {
"first_name": "Unknown", "last_name": "Owner"}
exposure = {
"name": dashboard["dashboard_title"] + " [dashboard]",
"type": "dashboard",
Expand All @@ -142,7 +146,7 @@ def sync_exposures( # pylint: disable=too-many-locals
else "low",
"url": str(client.baseurl / dashboard["url"].lstrip("/")),
"description": "",
"meta": { "id": f"d_{dashboard_id}" },
"meta": {"id": f"d_{dashboard_id}"},
"depends_on": get_dashboard_depends_on(client, dashboard, model_map),
"owner": {
"name": first_owner["first_name"] + " " + first_owner["last_name"],
Expand All @@ -152,4 +156,5 @@ def sync_exposures( # pylint: disable=too-many-locals
exposures.append(exposure)

with open(exposures_path, "w", encoding="utf-8") as output:
yaml.safe_dump({"version": 2, "exposures": exposures}, output, sort_keys=False)
yaml.safe_dump({"version": 2, "exposures": exposures},
output, sort_keys=False)

0 comments on commit 381cd47

Please sign in to comment.