Requesting a list response with an unsupported set leads to AttributeError

Issue #19 resolved
Toni Sissala created an issue

Reproduce:

curl "localhost:6003/v0/oai?verb=ListRecords&metadataPrefix=oai_dc&set=fsd"

Result:

<html><title>500: Internal Server Error</title><body>500: Internal Server Error</body></html>

Log output:

2020-12-03 13:59:27,617 ERROR(tornado.application): Uncaught exception GET /v0/oai?metadataPrefix=ead3&verb=ListRecords&set=fsd (xxx.xxx.xxx.xxx)
HTTPServerRequest(protocol='http', host='xxx.xxx.xxx.xxx:6003', method='GET', uri='/v0/oai?metadataPrefix=ead3&verb=ListRecords&set=fsd', version='HTTP/1.1', remote_ip='xxx.xxx.xxx.xxx')
Traceback (most recent call last):
  File "/venv/kuha2/lib/python3.5/site-packages/tornado/web.py", line 1703, in _execute
    result = await result
  File "/kuha_oai_pmh_repo_handler/kuha_oai_pmh_repo_handler/handlers.py", line 269, in get
    await self._router(args)
  File "/kuha_oai_pmh_repo_handler/kuha_oai_pmh_repo_handler/handlers.py", line 249, in _router
    await _route_callable()
  File "/kuha_oai_pmh_repo_handler/kuha_oai_pmh_repo_handler/genshi_loader.py", line 128, in wrapper
    context = await ctx_func(ctx)
  File "/kuha_oai_pmh_repo_handler/kuha_oai_pmh_repo_handler/handlers.py", line 164, in _list_records
    await self._handle_list_request(self._query_relative_records)
  File "/kuha_oai_pmh_repo_handler/kuha_oai_pmh_repo_handler/handlers.py", line 221, in _handle_list_request
    _filter=_filter
  File "/kuha_common/kuha_common/query.py", line 289, in query_count
    Query.construct(**kwargs),
  File "/kuha_common/kuha_common/document_store/query.py", line 270, in construct
    query_dict.update({key: value_builder_fun(value)})
  File "/kuha_common/kuha_common/document_store/query.py", line 76, in _build_filter
    path = field.path
AttributeError: 'NoneType' object has no attribute 'path'

Expected OAI response with error code “noRecordsMatch”

Proposed fix

diff --git a/kuha_oai_pmh_repo_handler/oai/records.py b/kuha_oai_pmh_repo_handler/oai/records.py                                                                                               
index 882ade9..cb28e21 100644                                                                                                                                                                  
--- a/kuha_oai_pmh_repo_handler/oai/records.py                                                                                                                                                 
+++ b/kuha_oai_pmh_repo_handler/oai/records.py                                                                                                                                                 
@@ -198,7 +198,10 @@ def get_query_filter_for_set(set_request):                                                                                                                                
         key, value = set_request.split(':')                                                                                                                                                   
     else:                                                                                                                                                                                     
         return None                                                                                                                                                                           
-    return {get_record_query_field_by_setspec(key): value}                                                                                                                                    
+    query_field = get_record_query_field_by_setspec(key)                                                                                                                                      
+    if query_field is None:                                                                                                                                                                   
+        return None                                                                                                                                                                           
+    return {query_field: value}

Comments (2)

  1. Toni Sissala reporter

    Release 0.12.1

    • Fix unhandled AttributeError when requesting a list response with an unsupported set-parameter. Respond with OAI error code "noRecordsMatch". (Fixes #19)

    → <<cset c543b6019a02>>

  2. Log in to comment