From 671c3339a4b2608c1862aff4542abf0490e2e375 Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Mon, 3 Feb 2025 10:06:03 +0100
Subject: [PATCH] Corrected _parse_distributions of ODSHDCATdeProfile to not
 rely on resource dict

---
 CHANGELOG.md                                  |  6 ++++++
 ckanext/odsh/profiles/odsh_dcat_de_profile.py | 18 ++++++++----------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 850f019..6d665e3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [Unreleased]
+
+### Fixed
+
+- Corrected `_parse_distributions` of `ODSHDCATdeProfile` to not rely on resource dict, fixing missing `id` errors.
+
 ## [2.5.0] - 2025-01-30
 
 ### Fixed
diff --git a/ckanext/odsh/profiles/odsh_dcat_de_profile.py b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
index eb57db6..0162e3f 100644
--- a/ckanext/odsh/profiles/odsh_dcat_de_profile.py
+++ b/ckanext/odsh/profiles/odsh_dcat_de_profile.py
@@ -42,18 +42,16 @@ class ODSHDCATdeProfile(DCATdeProfile):
             self._mark_for_adding_to_ckan_collection(dataset_dict, dataset_ref)
         return dataset_dict
 
+    # Duplicate licenseAttributionByText property of first distribution to extras
     def _parse_distributions(self, dataset_dict, dataset_ref):
         for distribution in self.g.objects(dataset_ref, DCAT.distribution):
-            for resource_dict in dataset_dict.get('resources', []):
-                # Match distribution in graph and distribution in ckan-dict
-                if str(distribution) == resource_uri(resource_dict):
-                    for namespace in [DCATDE, DCATDE_1_0, DCATDE_1_0_1, DCATDE_1_0_2]:
-                        value = self._object_value(
-                            distribution, namespace.licenseAttributionByText)
-                        if value:
-                            ds_utils.insert_new_extras_field(
-                                dataset_dict, 'licenseAttributionByText', value)
-                            return
+            for namespace in [DCATDE, DCATDE_1_0, DCATDE_1_0_1, DCATDE_1_0_2]:
+                value = self._object_value(
+                    distribution, namespace.licenseAttributionByText)
+                if value:
+                    ds_utils.insert_new_extras_field(
+                        dataset_dict, 'licenseAttributionByText', value)
+                    return
 
     def _parse_type(self, dataset_dict, dataset_ref):
         dct_type = self._object(dataset_ref, DCT.type)
-- 
GitLab