From 44b9046dda199a901fff8af699faceec92a64c4a Mon Sep 17 00:00:00 2001
From: Jean-Baptiste <bleme@pm.me>
Date: Mon, 18 Mar 2019 10:56:01 +0100
Subject: [PATCH] bugfix: correctly manage head of the graph

---
 djangoldp/serializers.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py
index d09bf524..29043b50 100644
--- a/djangoldp/serializers.py
+++ b/djangoldp/serializers.py
@@ -59,7 +59,7 @@ class LDListMixin:
             try:
                 list = next(
                     filter(lambda o: list[self.parent.url_field_name] == o[self.parent.url_field_name], object_list))
-            except (KeyError, TypeError):
+            except (KeyError, TypeError, StopIteration):
                 pass
 
             try:
@@ -350,8 +350,13 @@ class LDPSerializer(HyperlinkedModelSerializer):
     def get_value(self, dictionary):
         try:
             object_list = dictionary["@graph"]
-            container_id = Model.container_id(self.parent.instance)
-            obj = next(filter(lambda o: container_id in o[self.url_field_name], object_list))
+            if self.parent.instance is None:
+                obj = next(filter(
+                    lambda o: not hasattr(o, self.parent.url_field_name) or "./" in o[self.url_field_name],
+                    object_list))
+            else:
+                container_id = Model.container_id(self.parent.instance)
+                obj = next(filter(lambda o: container_id in o[self.url_field_name], object_list))
             item = super().get_value(obj)
             full_item = None
             if item is empty:
-- 
GitLab