From 3a7412d5ee66132b5693c3ddf6ae58b23eb57773 Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Thu, 13 Feb 2025 09:32:23 +0100
Subject: [PATCH] Fixed harvested datasets were incorrectly required to have a
 category set

---
 CHANGELOG.md               | 1 +
 ckanext/odsh/validation.py | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d665e3..b38e083 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
 ### Fixed
 
 - Corrected `_parse_distributions` of `ODSHDCATdeProfile` to not rely on resource dict, fixing missing `id` errors.
+- Resolved an issue where harvested datasets were incorrectly required to have a category set, even when the configuration variable `ckanext.odsh.require_at_least_one_category` was set to false.
 
 ## [2.5.0] - 2025-01-30
 
diff --git a/ckanext/odsh/validation.py b/ckanext/odsh/validation.py
index b49d362..186f408 100644
--- a/ckanext/odsh/validation.py
+++ b/ckanext/odsh/validation.py
@@ -32,7 +32,7 @@ def validate_extra_groups(data, requireAtLeastOne, errors):
     log.debug("Validating extra_groups")
     value = _extract_value(data, 'groups')
     error_message_no_group = 'at least one group needed'
-    if value != None:
+    if value is not None:
         # 'value != None' means the extra key 'groups' was found,
         # so the dataset came from manual editing via the web-frontend.
         if not value:
@@ -55,7 +55,7 @@ def validate_extra_groups(data, requireAtLeastOne, errors):
             data[('groups', num, 'id')] = group
     else:  # no extra-field 'groups'
         # dataset might come from a harvest process
-        if not data.get(('groups', 0, 'id'), False) and \
+        if requireAtLeastOne and not data.get(('groups', 0, 'id'), False) and \
            not data.get(('groups', 0, 'name'), False):
             errors['groups'] = error_message_no_group
 
-- 
GitLab