Closed giohappy closed 2 years ago
@giohappy can I have some steps on how to create this scenario.
We had a small discussion about the hierarchical keywords here: https://github.com/GeoNode/geonode/issues/6727
From my understanding, it would be best to assign all parent keywords to a resource. Eg:
geology - magmatic rocks - basalt
if basalt is used, the geology and magmatic rocks keywords are added, too. If you filter for geology-related resources it does not make sense to not show basalt features IMHO.
@gannebamm makes sense, but it will need some work. For the moment I would just fix the keywords filter.
@giohappy I tried to replicate your scenario, but I have a different result (always wrong)
Tested on the local instance in 4.x
Assuming the following scenario where:
external
is assigned to a datasetparent
: is not assigned to any datasetchild
is assigned to a datasetchild_of_child
is assigned to a datasetThe filter in UI is empty and from the backend, it raises an issue:
Traceback (most recent call last):
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/rest_framework/viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/rest_framework/views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/rest_framework/views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
raise exc
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/rest_framework/views.py", line 502, in dispatch
response = handler(request, *args, **kwargs)
File "/home/mattia/.virtualenvs/master/lib/python3.8/site-packages/rest_framework/mixins.py", line 38, in list
queryset = self.filter_queryset(self.get_queryset())
File "/opt/core/geonode/geonode/base/api/views.py", line 230, in get_queryset
resource_keywords = HierarchicalKeyword.resource_keywords_tree(self.request.user)
File "/opt/core/geonode/geonode/base/models.py", line 398, in resource_keywords_tree
tree = cls._keywords_tree_of_a_child(hkw, tree, newobj)
File "/opt/core/geonode/geonode/base/models.py", line 427, in _keywords_tree_of_a_child
item_found = find_by_attr(node["nodes"], newobj["id"])
KeyError: 'nodes'
"GET /api/v2/keywords?page_size=20&page=1 HTTP/1.1" 500 216989
Technically this issue should have fix by this https://github.com/GeoNode/geonode/issues/7750 but something is going wrong. I'm on it
Apparently, the only root keywords, from the hierarchical tree, are returned inside the keywords filter, with the following result:
Let's make an example
Keywords tree:
Filter (current behaviour):
You see that "a" is returned, since it's a parent of keywords with associated resources, and its number is 0 because it deosn't have resources directly associated
The expected results is: Filter:
i.e. the flattened keywords, with only the keywords with a direct association with one or more resources.