EGA-archive / beacon2-ri-api

Beacon v2 Reference Implementation (API)
Apache License 2.0
16 stars 38 forks source link

500 Internal Server Error Server got itself in trouble #259

Closed waakanni closed 9 months ago

waakanni commented 9 months ago

https://github.com/EGA-archive/beacon2-ri-api/blob/master/deploy/README.md#using-post When running this example post request http POST http://localhost:5050/api/biosamples --json < request.json on the test dataset on a local beacon install I get the above error.

Here is the log output of beacon:


beacon  | [beacon.request.handlers][DEBUG ] (L54) 10
beacon  | [beacon.request.handlers][DEBUG ] (L55) meta=RequestMeta(requested_schemas=[], api_version='2.0') query=RequestQuery(filters=[{'id': 'UBERON:0001256', 'scope': 'biosamples', 'includeDescendantTerms': False}], include_resultset_responses=<IncludeResultsetResponses.HIT: 'HIT'>, pagination=Pagination(skip=0, limit=10), request_parameters={}, test_mode=False, requested_granularity=<Granularity.COUNT: 'count'>)
beacon  | [beacon.request.handlers][DEBUG ] (L62) None
beacon  | [beacon.request.handlers][DEBUG ] (L72) public
beacon  | [beacon.utils.auth][DEBUG ] (L53) public
beacon  | [beacon.utils.auth][DEBUG ] (L60) ['CINECA_dataset', 'AV_Dataset', 'CINECA_synthetic_cohort_EUROPE_UK1']
beacon  | [beacon.request.handlers][DEBUG ] (L78) ['CINECA_dataset', 'AV_Dataset', 'CINECA_synthetic_cohort_EUROPE_UK1']
beacon  | [beacon.request.handlers][ INFO ] (L82) resolved datasets:  ['CINECA_dataset', 'AV_Dataset', 'CINECA_synthetic_cohort_EUROPE_UK1']
beacon  | [beacon.request.handlers][DEBUG ] (L83) True
beacon  | [beacon.request.handlers][DEBUG ] (L84) []
beacon  | [beacon.db.datasets][DEBUG ] (L27) Request parameters len = 1
beacon  | [beacon.db.datasets][DEBUG ] (L53) {}
beacon  | [beacon.db.utils][DEBUG ] (L28) Returning estimated count
beacon  | [beacon.db.utils][DEBUG ] (L37) FINAL QUERY: {}
beacon  | [beacon.request.handlers][DEBUG ] (L142) ['CINECA_dataset', 'AV_Dataset', 'CINECA_synthetic_cohort_EUROPE_UK1']
beacon  | [beacon.request.handlers][DEBUG ] (L145) []
beacon  | [beacon.request.handlers][DEBUG ] (L146) ['AV_Dataset', 'CINECA_synthetic_cohort_EUROPE_UK1']
beacon  | [beacon.db.biosamples][DEBUG ] (L28) Request parameters len = 0
beacon  | [beacon.db.filters][DEBUG ] (L21) Filters len = 1
beacon  | [beacon.db.filters][DEBUG ] (L41) Ontology filter: UBERON:0001256
beacon  | [beacon.db.filters][DEBUG ] (L44) {}
beacon  | [beacon.db.utils][DEBUG ] (L37) FINAL QUERY: {'$and': [{'scope': 'biosamples'}, {'id': 'UBERON:0001256'}]}
beacon  | [aiohttp.server][ERROR ] (L405) Error handling request
beacon  | Traceback (most recent call last):
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
beacon  |     resp = await request_handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
beacon  |     resp = await handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
beacon  |     return await handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 108, in impl
beacon  |     return await handler(request)
beacon  |   File "/beacon/beacon/response/middlewares.py", line 46, in error_middleware
beacon  |     return await handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp_middlewares/cors.py", line 255, in middleware
beacon  |     response = await handler(request)
beacon  |   File "/usr/local/lib/python3.10/site-packages/aiohttp_session/__init__.py", line 154, in factory
beacon  |     response = await handler(request)
beacon  |   File "/beacon/beacon/request/handlers.py", line 200, in wrapper
beacon  |     entity_schema, count, records = db_fn(entry_id, qparams)
beacon  |   File "/beacon/beacon/db/biosamples.py", line 45, in get_biosamples
beacon  |     query = apply_filters(query, qparams.query.filters, collection)
beacon  |   File "/beacon/beacon/db/filters.py", line 45, in apply_filters
beacon  |     partial_query = apply_ontology_filter(partial_query, filter, collection)
beacon  |   File "/beacon/beacon/db/filters.py", line 238, in apply_ontology_filter
beacon  |     dict_regex['$regex']=label
beacon  | UnboundLocalError: local variable 'label' referenced before assignment
beacon  | [aiohttp.access][ INFO ] (L206) 192.168.64.1 [18/Dec/2023:14:58:31 +0000] "POST /api/biosamples HTTP/1.1" 500 245 "-" "HTTPie/3.2.2"
costero-e commented 9 months ago

Hi @waakanni,

can you show what is your request.json file?

This error happens when you are trying to query by a filtering term you don't have in your filtering terms endpoint. So the beacon complains because it can't find a label for this id UBERON:0001256 inside filtering terms endpoint.

Best,

Oriol

waakanni commented 9 months ago

here:

{
    "meta": {
        "apiVersion": "2.0"
    },
    "query": {
        "filters": [
            {
                "id": "UBERON:0001256",
                "scope": "biosamples",
                "includeDescendantTerms": false
            }
        ],
        "includeResultsetResponses": "HIT",
        "pagination": {
            "skip": 0,
            "limit": 10
        },
        "testMode": false,
        "requestedGranularity": "count"
    }
}

Thanks

costero-e commented 9 months ago

Yes, is as I suspected. There is no filtering term for UBERON:0001256. If you run this other filtering term, UBERON:0000178, you will get some results as it appears by default in beacon reference implementation CINECA dataset. Try the request with request.json looking like this:

{
    "meta": {
        "apiVersion": "2.0"
    },
    "query": {
        "filters": [
            {
                "id": "UBERON:0000178",
                "scope": "biosamples",
                "includeDescendantTerms": false
            }
        ],
        "includeResultsetResponses": "HIT",
        "pagination": {
            "skip": 0,
            "limit": 10
        },
        "testMode": false,
        "requestedGranularity": "count"
    }
}

Thanks.

waakanni commented 9 months ago

This does indeed solves the issue. Can we update the documentation?

Thanks for all the help @costero-e

costero-e commented 9 months ago

Yes, I will update the documentation later this afternoon!

No problem @waakanni, thanks to you for the reporting.

Closing this issue now, let me know if you find any other.