From b6ac3c93c4d9dfe8398e3e52f174ba5892f14fb3 Mon Sep 17 00:00:00 2001
From: Calum Mackervoy <c.mackervoy@gmail.com>
Date: Sun, 24 May 2020 22:33:11 +0100
Subject: [PATCH] bugfix: nested container resolves as id-less container

---
 djangoldp/models.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/djangoldp/models.py b/djangoldp/models.py
index 9a8452bc..5cc1c3eb 100644
--- a/djangoldp/models.py
+++ b/djangoldp/models.py
@@ -118,13 +118,16 @@ class Model(models.Model):
     def resolve_id(cls, id):
         '''
         Resolves the id of a given path (e.g. /container/1/)
-        Raises ValidationError if the path has no id, a Resolver404 if the path cannot be found
+        Raises Resolver404 if the path cannot be found, ValidationError if the path is for a model base
         and an ObjectDoesNotExist exception if the resource does not exist
         '''
         id = cls.__clean_path(id)
-        view, args, kwargs = get_resolver().resolve(id)
-        if len(kwargs.keys()) == 0:
-            raise ValidationError('no id in given path')
+        match = get_resolver().resolve(id)
+        kwargs = match.kwargs
+        view = match.func
+
+        if match.url_name.endswith('-list') or len(match.kwargs.keys()) == 0:
+            raise ValidationError('resolve_id received a path for a container or nested container')
         return view.initkwargs['model'].objects.get(**kwargs)
 
     @classonlymethod
-- 
GitLab