From fbf7b5039bd41a454bd3793c3f0c2d05c4da130b Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Mon, 22 Apr 2024 12:33:12 +0200
Subject: [PATCH] fix publication metadata empty affiliations crash

truly fixes #255
reimplementation of 8a7b2a8b7d9b
---
 scipost_django/journals/models/publication.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scipost_django/journals/models/publication.py b/scipost_django/journals/models/publication.py
index 79ea588fb..478577f96 100644
--- a/scipost_django/journals/models/publication.py
+++ b/scipost_django/journals/models/publication.py
@@ -297,6 +297,10 @@ class Publication(models.Model):
             for idx, aff in enumerate(self.get_all_affiliations()):
                 if aff in author.affiliations.all():
                     affnrs.append(idx + 1)
+            # If no affiliation is found, add a None to the list
+            # Prevents crashes since Django v4
+            if len(affnrs) == 0:
+                affnrs = [None]
             indexed_author_list.append(affnrs)
         # Since nested ArrayFields must have the same dimension,
         # we pad the "empty" entries with Null:
-- 
GitLab