Requesting limit < total in /data/search/api causes TypeError
Using /data/search/api?limit=x where x is less than the total number of errors throws a TypeError.
Request Method: GET
Request URL: http://50.56.194.152:8000/data/search/api?limit=2
Django Version: 1.4
Exception Type: TypeError
Exception Value:
unsupported operand type(s) for -: 'builtin_function_or_method' and 'int'
Exception Location: /home/jay/web/geonode/src/GeoNodePy/geonode/maps/views.py in _metadata_search, line 1220
The code in question is below: ../geonode/src/GeoNodePy/geonode/maps/views.py in _metadata_search if start > 0: prev = max(start - limit, 0) params = urlencode({'q': query, 'start': prev, 'limit': limit}) result['prev'] = reverse('geonode.maps.views.metadata_search') + '?' + params next_page = csw.results.get('nextrecord', 0) if next_page > 0: params = urlencode({'q': query, 'start': next - 1, 'limit': limit}) ... result['next'] = reverse('geonode.maps.views.metadata_search') + '?' + params
return result
def search_result_detail(request): uuid = request.GET.get("uuid")
The problem is the next - 1 clause that gets called.
I think two things need to be done. In the maps_search function, that least if checks if next_page is less than the number of maps. I tried doing that and the error seems to go away. I did if next_page < len(results). I'm still relatively new to Python though, and I'm guessing that the second bit should be next_page - 1 instead of next - 1.
I believe this is fixed with this commit https://github.com/GeoNode/geonode/commit/adbbf1840b2e1308eeb1f4857a2c84b23b3ab45f
@jaywhy13 can you test and confirm.
I verified with different values of limit after that fix was applied, lower, equal and higher than the number of results and it works properly now. The edge case limit=0 causes a 500 error (CatalogueServiceWeb instance has no attribute 'results').
Since there is no way to do that from the interface we can close this. If someone wants to submit a patch for limit=0 I will be happy to take a look and merge it in.
Traceback:
File "/var/lib/geonode/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/var/lib/geonode/src/GeoNodePy/geonode/maps/views.py" in metadata_search
1174. result = _metadata_search(query, start, limit, **advanced)
File "/var/lib/geonode/src/GeoNodePy/geonode/maps/views.py" in _metadata_search
1211. 'total': csw.results['matches']}
Exception Type: AttributeError at /data/search/api
Exception Value: CatalogueServiceWeb instance has no attribute 'results'