From c1c73e690e7ab0b157c0bb53575a6564a44dc05b Mon Sep 17 00:00:00 2001 From: Linh Nguyen Date: Fri, 17 Nov 2023 11:48:11 -0500 Subject: [PATCH] Make sure that metadata `friendly_name` and `description` are not None (#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 * update test again --------- Co-authored-by: Alexander --- bigquery_etl/metadata/parse_metadata.py | 13 ++++++++++--- tests/metadata/test_parse_metadata.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bigquery_etl/metadata/parse_metadata.py b/bigquery_etl/metadata/parse_metadata.py index b8a684e3b4..630514904e 100644 --- a/bigquery_etl/metadata/parse_metadata.py +++ b/bigquery_etl/metadata/parse_metadata.py @@ -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 @@ -230,9 +232,14 @@ class Metadata: 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(): diff --git a/tests/metadata/test_parse_metadata.py b/tests/metadata/test_parse_metadata.py index 33027ca557..d13e6a068e 100644 --- a/tests/metadata/test_parse_metadata.py +++ b/tests/metadata/test_parse_metadata.py @@ -72,7 +72,7 @@ class TestParseMetadata(object): 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