Skip to content

Commit

Permalink
fix: Use get method to handle the unknown urls
Browse files Browse the repository at this point in the history
Usage of the square bracket notation raises KeyError for the unknown url.
Use get method providing a default value when the url is not found.
  • Loading branch information
kovalch authored Mar 1, 2024
1 parent 719b2bb commit 380d43d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ckanext/dcatapchharvest/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,15 @@ def _get_groups(self, subject):
if dcat_theme_url.startswith(OGD_THEMES_URI):
new_theme_url = dcat_theme_url.replace(
OGD_THEMES_URI, CHTHEMES_URI)
eu_theme_url = unicode(
eu_theme_mapping[URIRef(new_theme_url)][0])
eu_theme_url = eu_theme_mapping.get(
URIRef(new_theme_url), [None])[0]

# Case 2: We get a dcat-ap.ch theme (the same as the
# opendata.swiss themes, but different base url). Get
# the correct EU theme from the theme mapping.
elif dcat_theme_url.startswith(CHTHEMES_URI):
eu_theme_url = unicode(
eu_theme_mapping[URIRef(dcat_theme_url)][0])
eu_theme_url = eu_theme_mapping.get(
URIRef(new_theme_url), [None])[0]

# Case 3: We get an EU theme and don't need to look it up in
# the mapping.
Expand Down

0 comments on commit 380d43d

Please sign in to comment.