Skip to content
Snippets Groups Projects
Commit b6ac3c93 authored by Calum Mackervoy's avatar Calum Mackervoy
Browse files

bugfix: nested container resolves as id-less container

parent dcab4da1
No related branches found
No related tags found
1 merge request!130Resolve "DjangoLDP resolve_id error on container path"
Pipeline #5941 passed
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment