Skip to content

Commit

Permalink
Make sure that metadata friendly_name and description are not None (
Browse files Browse the repository at this point in the history
#4513)

* Fill empty description

* Assign a friendly name if the table doesn't have one

* Update metadata tests

* Update bigquery_etl/metadata/parse_metadata.py

Co-authored-by: Alexander <[email protected]>

* update test again

---------

Co-authored-by: Alexander <[email protected]>
  • Loading branch information
Iinh and ANich authored Nov 17, 2023
1 parent cbb843e commit c1c73e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions bigquery_etl/metadata/parse_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import enum
import os
import re
import string
from pathlib import Path
from typing import Any, Dict, List, Optional

import attr
Expand Down Expand Up @@ -230,9 +232,14 @@ def from_file(cls, metadata_file):
with open(metadata_file, "r") as yaml_stream:
try:
metadata = yaml.safe_load(yaml_stream)

friendly_name = metadata.get("friendly_name", None)
description = metadata.get("description", None)
table_name = str(Path(metadata_file).parent.name)
friendly_name = metadata.get(
"friendly_name", string.capwords(table_name.replace("_", " "))
)
description = metadata.get(
"description",
"Please provide a description for the query",
)

if "labels" in metadata:
for key, label in metadata["labels"].items():
Expand Down
2 changes: 1 addition & 1 deletion tests/metadata/test_parse_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_from_file(self):
metadata = Metadata.from_file(metadata_file)

assert metadata.friendly_name == "Test metadata file"
assert metadata.description is None
assert metadata.description == "Please provide a description for the query"
assert "schedule" in metadata.labels
assert metadata.labels["schedule"] == "daily"
assert "public_json" in metadata.labels
Expand Down

0 comments on commit c1c73e6

Please sign in to comment.