diff --git a/CHANGELOG.md b/CHANGELOG.md index 649af24..60a038c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `dcterms.bibliographicCitation` fields - Fixed regex so we run the comma space fix on `dcterms.bibliographicCitation` fields +- Don't crash the country/region checker/fixer when a title field is missing ### Changed - Don't run newline fix on description fields diff --git a/csv_metadata_quality/check.py b/csv_metadata_quality/check.py index 7f2d34b..ccf8378 100755 --- a/csv_metadata_quality/check.py +++ b/csv_metadata_quality/check.py @@ -563,8 +563,13 @@ def countries_match_regions(row, exclude): un_region = cc.convert(names=country, to="UNRegion") if un_region != "not found" and un_region not in regions: - print( - f"{Fore.YELLOW}Missing region ({country} → {un_region}): {Fore.RESET}{row[title_column_name]}" - ) + try: + print( + f"{Fore.YELLOW}Missing region ({country} → {un_region}): {Fore.RESET}{row[title_column_name]}" + ) + except KeyError: + print( + f"{Fore.YELLOW}Missing region ({country} → {un_region}): {Fore.RESET}" + ) return diff --git a/csv_metadata_quality/fix.py b/csv_metadata_quality/fix.py index cf948ed..b4f9c4a 100755 --- a/csv_metadata_quality/fix.py +++ b/csv_metadata_quality/fix.py @@ -370,9 +370,17 @@ def countries_match_regions(row, exclude): # it doesn't already exist in regions. if un_region != "not found" and un_region not in regions: if un_region not in missing_regions: - print( - f"{Fore.YELLOW}Adding missing region ({un_region}): {Fore.RESET}{row[title_column_name]}" - ) + try: + print( + f"{Fore.YELLOW}Adding missing region ({un_region}): {Fore.RESET}{row[title_column_name]}" + ) + except KeyError: + # If there is no title column in the CSV we will print + # the fix without the title instead of crashing. + print( + f"{Fore.YELLOW}Adding missing region ({un_region}): {Fore.RESET}<title field not present>" + ) + missing_regions.append(un_region) if len(missing_regions) > 0: